QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682601 | #9242. An Easy Geometry Problem | louhao088 | WA | 0ms | 8132kb | C++23 | 2.9kb | 2024-10-27 16:17:38 | 2024-10-27 16:17:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid (l+r>>1)
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
const int maxn=2e5+5,mod1=998244353,mod2=1019260817;
int x=0,n,m,q,l,r,a[maxn],k,b,c[maxn],v,op;
struct Hash{
int x1,x2;
}pw[maxn],base,B,sum1[maxn*4],sum2[maxn*4],Z;
bool operator < (Hash a,Hash b){if(a.x1==b.x1)return a.x2<b.x2;return a.x1<b.x1;}
bool operator == (Hash a,Hash b){return (a.x1==b.x1&&a.x2==b.x2);}
Hash operator + (Hash a,Hash b){return (Hash){(a.x1+b.x1)%mod1,(a.x2+b.x2)%mod2};}
Hash operator - (Hash a,Hash b){return (Hash){(a.x1-b.x1+mod1)%mod1,(a.x2-b.x2+mod2)%mod2};}
Hash operator * (Hash a,Hash b){return (Hash){1ll*(a.x1*b.x1)%mod1,1ll*(a.x2+b.x2)%mod2};}
void pushup(int rt,int l,int r){
sum1[rt]=sum1[ls]*pw[r-mid]+sum1[rs];
sum2[rt]=sum2[rs]+sum2[ls]*pw[mid-l+1];
}
void build(int rt,int l,int r){
if(l==r){
sum1[rt]=(Hash){(c[l]+mod1)%mod1,(c[l]+mod2)%mod2};
sum2[rt]=(Hash){(c[l]+mod1)%mod1,(c[l]+mod2)%mod2};
return;
}
build(ls,l,mid),build(rs,mid+1,r);
pushup(rt,l,r);
}
void upd(int rt,int l,int r,int pos,int x){
if(l>x||r<x)return ;
if(l==r){
sum1[rt]=(Hash){(c[l]+mod1)%mod1,(c[l]+mod2)%mod2};
sum2[rt]=(Hash){(c[l]+mod1)%mod1,(c[l]+mod2)%mod2};
return;
}
upd(ls,l,mid,pos,x),upd(rs,mid+1,r,pos,x);
pushup(rt,l,r);
}
Hash query1(int rt,int l,int r,int L,int R){
if(l>R||r<L)return Z;
if(l>=L&&r<=R)return sum1[rt];
if(L>mid)return query1(rs,mid+1,r,L,R);
if(R<=mid)return query1(ls,mid+1,r,L,R);
return query1(ls,l,mid,L,R)*pw[R-mid]+query1(rs,mid+1,r,L,R);
}
Hash query2(int rt,int l,int r,int L,int R){
if(l>R||r<L)return Z;
if(l>=L&&r<=R)return sum2[rt];
if(L>mid)return query2(rs,mid+1,r,L,R);
if(R<=mid)return query2(ls,mid+1,r,L,R);
return query2(ls,l,mid,L,R)+query2(rs,mid+1,r,L,R)*pw[mid-L+1];
}
signed main(){
n=read(),q=read(),k=read(),b=read();
b=b*2;
for(int i=1;i<=n;i++)a[i]=read()*2-i*k;
for(int i=1;i<=n;i++)c[i]=a[i]-a[i-1];
base=(Hash){23333,19937};pw[0]=(Hash){1,1};Z=(Hash){0,0};
for(int i=1;i<=n;i++)pw[i]=pw[i-1]*base;
build(1,1,n);
for(int i=1;i<=q;i++){
op=read();
if(op==1){
l=read(),r=read();v=read();v=v*2;
c[l]+=v;c[r+1]-=v;
upd(1,1,n,l,c[l]);if(r<n)upd(1,1,n,r+1,c[r+1]);
}
else if(op==2){
x=read();
if(c[x]+c[x+1]!=b||x==1||x==n){puts("0");continue;}
int l=2,r=min(x-1,n-x),res=1;
while(l<=r){
if(query1(1,1,n,x-mid+1,x-1)+query2(1,1,n,x+2,x+mid)==Z)res=mid,l=mid+1;
else r=mid-1;
}printf("%d\n",res);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7872kb
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: 0ms
memory: 8132kb
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:
617 400 796 219 456 412 255 65 17 520 90 692 1036 908 299 814 259 575 206 398 893 602 832 38 423 1027 529 42 653 51 933 523 699 763 355 125 1082 27 576 57 1041 163 239 92 22 96 716 233 843 60 457 501 280 849 918 935 345 211 76 906 466 851 302 1117 1066 265 7 173 1049 354 200 235 38 189 1027 52 1169 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '617'