QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682627#9242. An Easy Geometry Problemlouhao088WA 4ms10092kbC++233.0kb2024-10-27 16:30:432024-10-27 16:30:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-27 16:30:48]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10092kb
  • [2024-10-27 16:30:43]
  • 提交

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[ls]+sum2[rs]*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){
    if(l>pos||r<pos)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),upd(rs,mid+1,r,pos);
    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,l,mid,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,l,mid,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);if(r<n)upd(1,1,n,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;
            Hash A=query1(1,1,n,x-1,x-1),B=query2(1,1,n,x+2,x+2);
            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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 10092kb

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: 4ms
memory: 8192kb

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
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
0
2
2
2
2
2
2
1
2
2
2
2
2
2
2
...

result:

wrong answer 2nd numbers differ - expected: '304', found: '2'