QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#551433#9242. An Easy Geometry Problemucup-team4801#WA 12ms9344kbC++175.1kb2024-09-07 16:53:512024-09-07 16:53:51

Judging History

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

  • [2024-09-07 16:53:51]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:9344kb
  • [2024-09-07 16:53:51]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<random>
#include<chrono>
#include<cmath>

#define fi first
#define se second
#define mkp std::make_pair
using ll=long long;
using llu=unsigned long long;
using std::max;
using std::min;
template<class T> void cmax(T&a,T b){a=max(a,b);}
template<class T> void cmin(T&a,T b){a=min(a,b);}
template<class T> T sqr(T a){return a*a;}

const int NV=2e5;

int N,Q,K,B;

namespace hsh{
    const ll mod=1e9+7,bas=127;
    int pw[NV+5],spw[NV+5];
    struct HASH{
        ll val;
        int len;
        HASH&operator+=(ll x){
            //printf("x=%lld %lld %d ",x,val,len);
            val=(val+x*spw[len-1])%mod;
            //printf("%lld\n",val);
            return*this;
        }
    };
    HASH operator+(HASH a,HASH b){
        return {((ll)a.val*pw[b.len]+b.val)%mod,a.len+b.len};
    }
    void init(){
        pw[0]=1;
        spw[0]=1;
        for(int i=1;i<NV+5;++i)
            spw[i]=(spw[i-1]+(pw[i]=pw[i-1]*bas%mod))%mod;
    }
}

struct SEG{
    struct SEGN{
        hsh::HASH a;
        ll tad;
    } tr[NV*4+5];
    inline void up(int x){
        tr[x].a=tr[x*2].a+tr[x*2+1].a;
    }inline void doadd(int x,ll z){
        tr[x].a+=z;
        tr[x].tad+=z;
    }inline void dn(int x){
        if(tr[x].tad){
            doadd(x*2,tr[x].tad);
            doadd(x*2+1,tr[x].tad);
            tr[x].tad=0;
        }
    }void add(int x,int l,int r,int ql,int qr,ll z){
        int mid=l+r>>1;
        if(ql<=l&&r<=qr) doadd(x,z);
        else{
            dn(x);
            if(ql<=mid) add(x*2,l,mid,ql,qr,z);
            if(mid<qr) add(x*2+1,mid+1,r,ql,qr,z);
            up(x);
        }
    }hsh::HASH que(int x,int l,int r,int ql,int qr){
        if(ql<=l&&r<=qr) return tr[x].a;
        int mid=l+r>>1;
        dn(x);
        if(qr<=mid) return que(x*2,l,mid,ql,qr);
        if(mid<ql) return que(x*2+1,mid+1,r,ql,qr);
        //printf("[%d,%d],[%d,%d] %lld %lld %lld\n",l,mid,mid+1,r,que(x*2,l,mid,ql,qr),que(x*2+1,mid+1,r,ql,qr),que(x*2,l,mid,ql,qr)+que(x*2+1,mid+1,r,ql,qr));

        return que(x*2,l,mid,ql,qr)+que(x*2+1,mid+1,r,ql,qr);
    }void build(int x,int l,int r,int*a){
        if(l==r){
            tr[x].a.len=1;
            tr[x].a.val=a[l];
        }else{
            int mid=l+r>>1;
            build(x*2,l,mid,a);
            build(x*2+1,mid+1,r,a);
            up(x);
        }
    }void dfs(int x,int l,int r){
        if(l==r){
            printf("%d [%d,%d] %lld %d\n",x,l,r,tr[x].a.val,tr[x].a.len);
        }else{
            dn(x);
            dfs(x*2,l,l+r>>1);
            printf("%d [%d,%d] %lld %d\n",x,l,r,tr[x].a.val,tr[x].a.len);
            dfs(x*2+1,(l+r>>1)+1,r);
        }
    }
};

namespace xm{
    SEG tr,rt;
    int A[NV+5],rA[NV+5];
    void _(){
        scanf("%d%d%d%d",&N,&Q,&K,&B);
        hsh::init();
        for(int i=1;i<=N;++i) scanf("%d",A+i);
        for(int i=1;i<=N;++i) A[i]=A[i]*2-K*i;
        memcpy(rA+1,A+1,sizeof*A*N);
        std::reverse(rA+1,rA+N+1);
        for(int i=1;i<=N;++i) rA[i]+=B*2;

        tr.build(1,1,N,A);
        rt.build(1,1,N,rA);
        while(Q--){
            short op;

            scanf("%hd",&op);
            if(op==1){
                int l,r,v;
                scanf("%d%d%d",&l,&r,&v);
                tr.add(1,1,N,l,r,v*2ll);
                rt.add(1,1,N,N-r+1,N-l+1,v*2ll);
                //for(int i=l;i<=r;++i){
                //    A[i]+=v*2;
                //    rA[N-i+1]+=v*2;
                //}
            }else{
                int x;
                scanf("%d",&x);
                //for(int i=1;i<=N;++i){
                //    A[i]+=x*K;
                //    rA[N-i+1]+=x*K;
                //}
                tr.doadd(1,(ll)x*K);
                rt.doadd(1,(ll)x*K);
                //for(int i=1;i<=N;++i) printf("%lld ",tr.que(1,1,N,i,i).val);
                //puts("");
                //for(int i=1;i<=N;++i) printf("%lld ",rt.que(1,1,N,i,i).val);
                //puts("");
                int L=0,R=min(N-x+1,x);
                //printf("L=%d R=%d\n",L,R);
                //if(Q==5){
                //    printf("que [%d,%d],[%d,%d]\n",x+1,x+3,N-x+2,N-x+1+3);
                //    printf("%lld %lld\n",tr.que(1,1,N,x+1,x+3).val
                //            ,rt.que(1,1,N,N-x+2,N-x+1+3).val);
                //}
                while(L+1<R){
                    int mid=L+R>>1;
                    //printf("que [%d,%d],[%d,%d]\n",x+1,x+mid-1,N-x+2,N-x+1+mid);
                    if(tr.que(1,1,N,x+1,x+mid).val
                            ==rt.que(1,1,N,N-x+2,N-x+1+mid).val)
                        L=mid;
                    else R=mid;
                }
                printf("%d\n",L);
                tr.doadd(1,-(ll)x*K);
                rt.doadd(1,-(ll)x*K);
                //for(int i=1;i<=N;++i){
                //    A[i]-=x*K;
                //    rA[N-i+1]-=x*K;
                //}
            }
            //tr.dfs(1,1,N);
            //rt.dfs(1,1,N);
        }
    }
}

int main(){
    xm::_();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8260kb

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: 12ms
memory: 9344kb

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
4
61
292
139
48
17
99
6
5
53
93
3
91
4
29
4
306
21
24
17
21
281
12
16
1
33
7
3
96
7
40
3
13
7
46
43
16
1
72
3
4
22
5
6
189
27
1
35
107
43
34
3
27
20
21
44
56
96
36
2
4
22
30
32
6
5
105
3
37
12
58
2
21
154
17
110
57
3
7
33
4
24
94
68
4
1
14
4
4
3
2
25
39
36
33
164
4
4
181
11
4
3
50
10
51
76
...

result:

wrong answer 4th numbers differ - expected: '29', found: '4'