QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682638#9242. An Easy Geometry Problemlouhao088WA 4ms10108kbC++233.0kb2024-10-27 16:35:572024-10-27 16:35:57

Judging History

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

  • [2024-10-27 16:35:57]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10108kb
  • [2024-10-27 16:35:57]
  • 提交

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: 1ms
memory: 7936kb

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: 10108kb

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 525th numbers differ - expected: '12', found: '20'