Nice boat
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 24 Accepted Submission(s): 9
Problem Description
There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.
Let us continue our story, z*p(actually you) defeat the 'MengMengDa' party's leader, and the 'MengMengDa' party dissolved. z*p becomes the most famous guy among the princess's knight party.
One day, the people in the party find that z*p has died. As what he has done in the past, people just say 'Oh, what a nice boat' and don't care about why he died.
Since then, many people died but no one knows why and everyone is fine about that. Meanwhile, the devil sends her knight to challenge you with Algorithm contest.
There is a hard data structure problem in the contest:
There are n numbers a_1,a_2,...,a_n on a line, everytime you can change every number in a segment [l,r] into a number x(type 1), or change every number a_i in a segment [l,r] which is bigger than x to gcd(a_i,x) (type 2).
You should output the final sequence.
Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains a integers n.
The next line contains n integers a_1,a_2,...,a_n separated by a single space.
The next line contains an integer Q, denoting the number of the operations.
The next Q line contains 4 integers t,l,r,x. t denotes the operation type.
T<=2,n,Q<=100000
a_i,x >=0
a_i,x is in the range of int32(C++)
Output
For each test case, output a line with n integers separated by a single space representing the final sequence.
Please output a single more space after end of the sequence
Sample Input
1
10
16807 282475249 1622650073 984943658 1144108930 470211272 101027544 1457850878 1458777923 2007237709
10
1 3 6 74243042
2 4 8 16531729
1 3 4 1474833169
2 1 8 1131570933
2 7 9 1505795335
2 3 7 101929267
1 4 10 1624379149
2 2 8 2110010672
2 6 7 156091745
1 2 5 937186357
Sample Output
16807 937186357 937186357 937186357 937186357 1 1 1624379149 1624379149 1624379149
Source
2014 Multi-University Training Contest 4
题意:输入一段数,有两个操作,1表示把一段区间内的数变成x,2表示把一段区间内的数如果这个数大于x则变为这个数与x的最小公约数,否则不变。最后输出变化后的一组数。
用线段树写的,主要是利用延迟标记,全部变成x的话直接把这段变成x,然后加个延迟标记就行了,如果往下更新,要把延迟标记和数一起往下传,查询的时候如果延迟标记存在的话直接把这一段输出,因为延迟标记存在这一段肯定是相同的数。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int MAXN=100010;
int num[MAXN];
struct tree
{
int l,r;
int mark;
int sum;
}tree[MAXN<<2];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
void build(int l,int r,int k)
{
tree[k].l=l;
tree[k].r=r;
tree[k].mark=0;
if(l==r)
{
tree[k].sum=num[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,k<<1);
build(mid+1,r,k<<1|1);
}
void pushdown(int k)
{
if(tree[k].mark)
{
tree[k<<1].mark=tree[k<<1|1].mark=tree[k].mark;
tree[k<<1].sum=tree[k<<1|1].sum=tree[k].sum;
tree[k].mark=0;
}
}
void update(int l,int r,int k,int x) //代表1的更新
{
if(tree[k].l>=l&&tree[k].r<=r)
{
tree[k].sum=x;
tree[k].mark=1;
return;
}
pushdown(k);
int mid=(tree[k].l+tree[k].r)>>1;
if(r<=mid)
update(l,r,k<<1,x);
else if(l>mid)
update(l,r,k<<1|1,x);
else
{
update(l,mid,k<<1,x);
update(mid+1,r,k<<1|1,x);
}
}
void update1(int l,int r,int k,int x) //代表2的更新
{
if(tree[k].mark)
{
if(tree[k].l>=l&&tree[k].r<=r)
{
if(tree[k].sum<=x)
return;
else
{
tree[k].sum=gcd(tree[k].sum,x);
return;
}
}
}
if(tree[k].l==tree[k].r)
{
if(tree[k].sum>x)
tree[k].sum=gcd(tree[k].sum,x);
tree[k].mark=0;
return;
}
pushdown(k);
int mid=(tree[k].l+tree[k].r)>>1;
if(r<=mid)
update1(l,r,k<<1,x);
else if(l>mid)
update1(l,r,k<<1|1,x);
else
{
update1(l,mid,k<<1,x);
update1(mid+1,r,k<<1|1,x);
}
}
void prin(int k) //输出
{
if(tree[k].l==tree[k].r)
{
printf("%d ",tree[k].sum);
return;
}
if(tree[k].mark)
{
for(int i=tree[k].l;i<=tree[k].r;i++)
{
printf("%d ",tree[k].sum);
}
return ;
}
prin(k<<1);
prin(k<<1|1);
}
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&num[i]);
int m;
scanf("%d",&m);
int op;
build(1,n,1);
while(m--)
{
scanf("%d",&op);
if(op==1)
{
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
update(l,r,1,x);
}
else
{
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
update1(l,r,1,x);
}
}
prin(1);
printf("\n");
}
return 0;
}

本文深入探讨了AI音视频处理和图像处理AR特效领域的前沿技术,包括视频分割语义识别、自动驾驶、AR、SLAM等,以及OpenGL、OpenCV、GPU加速等关键技术的应用。同时,文章还涉及图像色彩空间、视频编解码算法、音频编解码算法等基础概念,为读者提供了一个全面的技术视角。
853

被折叠的 条评论
为什么被折叠?



