QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#550771 | #9242. An Easy Geometry Problem | ucup-team3510# | WA | 13ms | 21276kb | C++20 | 2.9kb | 2024-09-07 14:14:44 | 2024-09-07 14:14:45 |
Judging History
answer
#include <bits/stdc++.h>
#define N 200011
using namespace std;
int n,q,k,b,a[N];
const int P[2]={1028838407,1013333903};
struct mint{int x[2];mint(){x[0]=x[1]=0;}mint(int _x){x[0]=_x;x[1]=_x;}mint(int _a,int _b){x[0]=_a;x[1]=_b;}};
mint operator+(mint a,mint b){return mint((a.x[0]+b.x[0])%P[0],(a.x[1]+b.x[1])%P[1]);}
mint operator-(mint a,mint b){return mint((a.x[0]+P[0]-b.x[0])%P[0],(a.x[1]+P[1]-b.x[1])%P[1]);}
mint operator*(mint a,mint b){return mint(1ll*a.x[0]*b.x[0]%P[0],1ll*a.x[1]*b.x[1]%P[1]);}
bool operator==(mint a,mint b){return a.x[0]==b.x[0]&&a.x[1]==b.x[1];}
mint pw[N],spw[N];
const int B=801801801;
mint lsum[N*4],rsum[N*4];
void pushup(int x,int L,int R)
{
int M=L+R>>1;
lsum[x]=lsum[x<<1]*pw[R-M]+lsum[x<<1|1];
rsum[x]=rsum[x<<1]+rsum[x<<1|1]*pw[M-L+1];
}
int tag[N*4];
void apply(int x,int p,int L,int R)
{
lsum[x]=lsum[x]+p*spw[R-L];
rsum[x]=rsum[x]+p*spw[R-L];
tag[x]+=p;
}
void pushdown(int x,int L,int R)
{
if(tag[x])
{
apply(x<<1,tag[x],L,L+R>>1);
apply(x<<1|1,tag[x],(L+R>>1)+1,R);
tag[x]=0;
}
}
void build(int L,int R,int x)
{
if(L==R){lsum[x]=rsum[x]=mint((a[L]-(k/2)*L+P[0])%P[0],(a[L]-(k/2)*L+P[1])%P[1]);return;}
build(L,L+R>>1,x<<1);build((L+R>>1)+1,R,x<<1|1);pushup(x,L,R);
}
mint lquery(int l,int r,int L,int R,int x)
{
if(l<=L&&R<=r)return lsum[x];pushdown(x,L,R);
if(l<=L+R>>1&&r>L+R>>1)
{
mint lv=lquery(l,r,L,L+R>>1,x<<1);
mint rv=lquery(l,r,(L+R>>1)+1,R,x<<1|1);
return lv*pw[min(r,R)-(L+R>>1)]+rv;
}
if(l<=L+R>>1)return lquery(l,r,L,L+R>>1,x<<1);return lquery(l,r,(L+R>>1)+1,R,x<<1|1);
}
mint rquery(int l,int r,int L,int R,int x)
{
if(l<=L&&R<=r)return rsum[x];pushdown(x,L,R);
if(l<=L+R>>1&&r>L+R>>1)
{
mint lv=lquery(l,r,L,L+R>>1,x<<1);
mint rv=lquery(l,r,(L+R>>1)+1,R,x<<1|1);
return rv*pw[(L+R>>1)-max(l,L)+1]+lv;
}
if(l<=L+R>>1)return rquery(l,r,L,L+R>>1,x<<1);return rquery(l,r,(L+R>>1)+1,R,x<<1|1);
}
void add(int l,int r,int p,int L,int R,int x)
{
if(l<=L&&R<=r){apply(x,p,L,R);return;}pushdown(x,L,R);
if(l<=L+R>>1)add(l,r,p,L,L+R>>1,x<<1);if(r>L+R>>1)add(l,r,p,(L+R>>1)+1,R,x<<1|1);pushup(x,L,R);
}
int main()
{
scanf("%d%d%d%d",&n,&q,&k,&b);
for(int i=1;i<=n;++i)scanf("%d",a+i),a[i]*=2;
pw[0]=1;for(int i=1;i<N;++i)pw[i]=pw[i-1]*B;
spw[0]=1;for(int i=1;i<N;++i)spw[i]=spw[i-1]+pw[i];
k*=2;b*=2;
build(1,n,1);
while(q--)
{
int cmd;
scanf("%d",&cmd);
if(cmd==1)
{
int l,r,v;scanf("%d%d%d",&l,&r,&v);v*=2;
add(l,r,v,1,n,1);
}
else
{
int i;scanf("%d",&i);
int L=1,R=min(i-1,n-i),ans=0;
while(L<=R)
{
int M=L+R>>1;
// printf("[%d,%d]:{%d,%d} [%d,%d]:{%d,%d}\n",i-M,i-1,lquery(i-M,i-1,1,n,1).x[0],lquery(i-M,i-1,1,n,1).x[1],i+1,i+M,rquery(i+1,i+M,1,n,1).x[0],rquery(i+1,i+M,1,n,1).x[1]);
if(lquery(i-M,i-1,1,n,1)+b*spw[M-1]==rquery(i+1,i+M,1,n,1))ans=M,L=M+1;else R=M-1;
}
printf("%d\n",ans);
}
}
fclose(stdin);fclose(stdout);return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 21276kb
input:
6 6 6 2 1 5 9 10 15 18 2 2 1 3 3 -3 2 2 1 3 4 3 2 3 2 4
output:
1 0 2 0
result:
ok 4 number(s): "1 0 2 0"
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 20248kb
input:
5000 5000 2 0 -329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...
output:
2 304 73 29 61 292 139 48 17 99 6 5 53 93 3 91 65 29 33 306 21 24 17 21 281 12 16 1 33 7 18 96 7 40 39 13 7 46 43 16 1 72 33 16 22 5 6 189 27 1 35 107 43 34 3 27 20 21 44 56 96 36 2 27 22 30 32 6 5 105 27 37 12 58 2 21 154 17 110 57 3 7 33 15 24 94 68 25 1 14 10 4 10 2 25 39 36 33 164 11 19 181 11 3...
result:
wrong answer 123rd numbers differ - expected: '9', found: '20'