QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679134 | #9242. An Easy Geometry Problem | louhao088# | WA | 9ms | 10028kb | C++23 | 3.8kb | 2024-10-26 16:57:31 | 2024-10-26 16:57:31 |
Judging History
answer
#include<bits/stdc++.h>
#define Lson (now<<1)
#define Rson (now<<1|1)
using namespace std;
const int MAXN=2e5,SIZE=524288;
const int Base=2333,MOD=1e9+7,mod=1019260817;
inline int Read()
{
int res=0,sgn=1;char c;
while(1) {c=getchar();if(c=='-') {sgn=-1;break;}if('0'<=c && c<='9') {res=c-'0';break;}}
while(1) {c=getchar();if('0'<=c && c<='9') res=res*10+c-'0';else break;}
return sgn*res;
}
inline int plu(int a,int b) {return a+b-(a+b>=MOD)*MOD;}
inline int mul(int a,int b) {return 1ll*a*b%MOD;}
inline int ABS(int x)
{
if(x>=MOD) x-=MOD;
if(x<0) x+=MOD;
return x;
}
inline int plu1(int a,int b) {return a+b-(a+b>=mod)*mod;}
inline int mul1(int a,int b) {return 1ll*a*b%mod;}
inline int ABS1(int x)
{
if(x>=mod) x-=mod;
if(x<0) x+=mod;
return x;
}
int n,q,K,B,A[MAXN+5],pw[MAXN+5],sum[SIZE+5][2];
int pw1[MAXN+5],sum1[SIZE+5][2],A1[MAXN];
inline void PushUp(int now,int len)
{
sum[now][0]=plu(sum[Lson][0],mul(pw[(len+1)>>1],sum[Rson][0]));
sum[now][1]=plu(mul(pw[len>>1],sum[Lson][1]),sum[Rson][1]);
sum1[now][0]=plu1(sum1[Lson][0],mul1(pw1[(len+1)>>1],sum1[Rson][0]));
sum1[now][1]=plu1(mul1(pw1[len>>1],sum1[Lson][1]),sum1[Rson][1]);
}
void Build(int now,int L,int R)
{
if(L==R) {
sum[now][0]=sum[now][1]=A[L];
sum1[now][0]=sum1[now][1]=A1[L];
return;
}
int mid=(L+R)>>1;
Build(Lson,L,mid);
Build(Rson,mid+1,R);
PushUp(now,R-L+1);
}
void Modify(int now,int L,int R,int x,int v,int v1)
{
if(L==R) {
sum[now][0]=plu(sum[now][0],v),sum[now][1]=plu(sum[now][1],v);
sum1[now][0]=plu1(sum1[now][0],v1),sum1[now][1]=plu1(sum1[now][1],v1);
return;
}
int mid=(L+R)>>1;
if(x<=mid) Modify(Lson,L,mid,x,v,v1);
else Modify(Rson,mid+1,R,x,v,v1);
PushUp(now,R-L+1);
}
int Hash0(int now,int L,int R,int QL,int QR)
{
if(QR<L || R<QL) return 0;
if(QL<=L && R<=QR) return mul(pw[L-QL],sum[now][0]);
int mid=(L+R)>>1;
return plu(Hash0(Lson,L,mid,QL,QR),Hash0(Rson,mid+1,R,QL,QR));
}
int Hash1(int now,int L,int R,int QL,int QR)
{
if(QR<L || R<QL) return 0;
if(QL<=L && R<=QR) return mul(pw[QR-R],sum[now][1]);
int mid=(L+R)>>1;
return plu(Hash1(Lson,L,mid,QL,QR),Hash1(Rson,mid+1,R,QL,QR));
}
int Hash01(int now,int L,int R,int QL,int QR)
{
if(QR<L || R<QL) return 0;
if(QL<=L && R<=QR) return mul1(pw[L-QL],sum[now][0]);
int mid=(L+R)>>1;
return plu1(Hash01(Lson,L,mid,QL,QR),Hash01(Rson,mid+1,R,QL,QR));
}
int Hash11(int now,int L,int R,int QL,int QR)
{
if(QR<L || R<QL) return 0;
if(QL<=L && R<=QR) return mul1(pw1[QR-R],sum1[now][1]);
int mid=(L+R)>>1;
return plu1(Hash11(Lson,L,mid,QL,QR),Hash11(Rson,mid+1,R,QL,QR));
}
int Ask(int now,int L,int R,int x)
{
if(L==R) return sum[now][0];
int mid=(L+R)>>1;
if(x<=mid) return Ask(Lson,L,mid,x);
return Ask(Rson,mid+1,R,x);
}
int main()
{
n=Read(),q=Read(),K=Read(),B=Read();
B=ABS(2*B);
for(int i=1;i<=n;i++) A[i]=2*Read()-K*i;
for(int i=n;i;i--) A[i]-=A[i-1];
for(int i=1;i<=n;i++) A[i]=ABS(A[i]),A1[i]=ABS1(A[i]);
pw[0]=1;pw1[0]=1;
for(int i=1;i<=n;i++){
pw[i]=mul(pw[i-1],Base);
pw1[i]=mul(pw1[i-1],Base);
}
Build(1,1,n);
for(int opt,L,R,x;q--;)
{
opt=Read();
if(opt==1)
{
L=Read(),R=Read(),x=Read();
Modify(1,1,n,L,ABS(2*x),ABS1(2*x)); if(R<n) Modify(1,1,n,R+1,ABS(-2*x),ABS1(-2*x));
}
else
{
x=Read();
if(x==1 || x==n) {puts("0");continue;}
if(plu(Ask(1,1,n,x),Ask(1,1,n,x+1))!=B) {puts("0");continue;}
//printf("well\n");
L=2,R=min(x,n-x);
for(int mid;L<=R;)
{
mid=(L+R)>>1;
if(plu(Hash0(1,1,n,x-mid+1,x-1),Hash1(1,1,n,x+2,x+mid))||plu1(Hash01(1,1,n,x-mid+1,x-1),Hash11(1,1,n,x+2,x+mid))) R=mid-1;
else L=mid+1;
}
printf("%d\n",R);
}
}
return 0;
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9888kb
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: 9ms
memory: 10028kb
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 349th numbers differ - expected: '25', found: '1'