QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688349 | #9242. An Easy Geometry Problem | ucup-team5351 | WA | 9ms | 4040kb | C++20 | 4.8kb | 2024-10-30 06:12:16 | 2024-10-30 06:12:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#define ALL(v) v.begin(),v.end()
#define For(i,_) for(int i=0,i##end=_;i<i##end;++i) // [0,_)
#define FOR(i,_,__) for(int i=_,i##end=__;i<i##end;++i) // [_,__)
#define Rep(i,_) for(int i=(_)-1;i>=0;--i) // [0,_)
#define REP(i,_,__) for(int i=(__)-1,i##end=_;i>=i##end;--i) // [_,__)
typedef long long ll;
typedef unsigned long long ull;
#define V vector
#define pb push_back
#define pf push_front
#define qb pop_back
#define qf pop_front
#define eb emplace_back
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define fi first
#define se second
const int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}},inf=0x3f3f3f3f,mod=1e9+7;
const ll infl=0x3f3f3f3f3f3f3f3fll;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
int init=[](){return cin.tie(nullptr)->sync_with_stdio(false),0;}();
int main(){
int t_case=1;
//scanf("%d",&t_case);
while(t_case--){
int b,k,n,q;
scanf("%d%d%d%d",&n,&q,&k,&b);
b=(2*b%mod+mod)%mod;
V<ull>bs(n+1),pre(n+1);
bs[0]=pre[0]=1;
For(i,n)(pre[i+1]=pre[i]+(bs[i+1]=bs[i]*233%mod))%=mod;
V<int>a(n);
For(i,n){
scanf("%d",&a[i]);
(((a[i]*=2)-=i*k)+=998244353)%=mod;
}
V<ull>h(n<<2),h2(n<<2);
auto build=[&](auto &&self,int p,int l,int r){
if(l==r){
h[p]=h2[p]=a[l];
return;
}
int mid=l+r>>1;
self(self,p<<1,l,mid),self(self,p<<1|1,mid+1,r);
h[p]=(h[p<<1]*bs[r-mid]+h[p<<1|1])%mod,h2[p]=(h2[p<<1]+h2[p<<1|1]*bs[mid-l+1])%mod;
};
build(build,1,0,n-1);
V<int>tag(n<<2);
auto modify=[&](auto &&self,int p,int l,int r,int ql,int qr,int v){
if(ql<=l&&r<=qr){
ull add=pre[r-l]*v%mod;
(h[p]+=add)%=mod,(h2[p]+=add)%=mod,(tag[p]+=v)%=mod;
return;
}
int mid=l+r>>1;
if(tag[p]){
ull add=pre[mid-l]*tag[p]%mod;
(h[p<<1]+=add)%=mod,(h2[p<<1]+=add)%=mod,(tag[p<<1]+=tag[p])%=mod;
add=pre[r-mid-1]*tag[p];
(h[p<<1|1]+=add)%=mod,(h2[p<<1|1]+=add)%=mod,(tag[p<<1|1]+=tag[p])%=mod;
tag[p]=0;
return;
}
if(ql<=mid)self(self,p<<1,l,mid,ql,qr,v);
if(qr>mid)self(self,p<<1|1,mid+1,r,ql,qr,v);
h[p]=h[p<<1]*bs[r-mid]+h[p<<1|1],h2[p]=h2[p<<1]+h2[p<<1|1]*bs[mid-l+1];
};
ull ans;
auto query=[&](auto &&self,int p,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr){
ans=(ans*bs[r-l+1]+h[p])%mod;
return;
}
int mid=l+r>>1;
if(tag[p]){
ull add=pre[mid-l]*tag[p]%mod;
(h[p<<1]+=add)%=mod,(h2[p<<1]+=add)%=mod,(tag[p<<1]+=tag[p])%=mod;
add=pre[r-mid-1]*tag[p];
(h[p<<1|1]+=add)%=mod,(h2[p<<1|1]+=add)%=mod,(tag[p<<1|1]+=tag[p])%=mod;
tag[p]=0;
return;
}
if(ql<=mid)self(self,p<<1,l,mid,ql,qr);
if(qr>mid)self(self,p<<1|1,mid+1,r,ql,qr);
};
ull ans2;
auto query2=[&](auto &&self,int p,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr){
ans2=(h2[p]+ans2*bs[r-l+1])%mod;
return;
}
int mid=l+r>>1;
if(tag[p]){
ull add=pre[mid-l]*tag[p]%mod;
(h[p<<1]+=add)%=mod,(h2[p<<1]+=add)%=mod,(tag[p<<1]+=tag[p])%=mod;
add=pre[r-mid-1]*tag[p];
(h[p<<1|1]+=add)%=mod,(h2[p<<1|1]+=add)%=mod,(tag[p<<1|1]+=tag[p])%=mod;
tag[p]=0;
return;
}
if(qr>mid)self(self,p<<1|1,mid+1,r,ql,qr);
if(ql<=mid)self(self,p<<1,l,mid,ql,qr);
};
while(q--){
int op;
scanf("%d",&op);
if(op&1){
int l,r,v;
scanf("%d%d%d",&l,&r,&v);
v=(v*2%mod+mod)%mod;
modify(modify,1,0,n-1,l-1,r-1,v);
}
else{
int k;
scanf("%d",&k),--k;
int ez=0,l=1,r=min(k,n-1-k);
while(l<=r){
int mid=l+r>>1;
ans=ans2=0;
query(query,1,0,n-1,k-mid,k-1),query2(query2,1,0,n-1,k+1,k+mid);
if((ans+b*pre[mid-1])%mod==ans2)ez=mid,l=mid+1;
else r=mid-1;
}
printf("%d\n",ez);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
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: 4040kb
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 572nd numbers differ - expected: '12', found: '10'