QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672195 | #9242. An Easy Geometry Problem | Double_u | WA | 1ms | 9732kb | C++14 | 3.5kb | 2024-10-24 16:00:08 | 2024-10-24 16:00:09 |
Judging History
answer
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int MAXN=4e5+5;
const int MAXK=4e3+5;
const int seed=2333;
const int MOD=998244353;
int n,q,k,b;
long long a[MAXN],c[MAXN],tr1[MAXN*4],tr2[MAXN*4],tag1[MAXN*4],tag2[MAXN*4],pre[MAXN],qp[MAXN];
void prep(){
qp[0]=1;
for(int i=1;i<=n;i++){
qp[i]=qp[i-1]*seed%MOD;
pre[i]=(pre[i-1]+qp[i-1])%MOD;
}
}
void pushup(int rt,int l,int r){
int mid=l+r>>1;
tr1[rt]=(tr1[rt<<1]*qp[r-mid]%MOD+tr1[rt<<1|1])%MOD;
tr2[rt]=(tr2[rt<<1]*qp[r-mid]%MOD+tr2[rt<<1|1])%MOD;
}
void build(int rt,int l,int r,int opt){
if(l==r){
if(!opt) tr1[rt]=c[l]%MOD;
else tr2[rt]=(c[n-l+1]-(long long)2*b+(long long)2*MOD)%MOD;
return ;
}
int mid=l+r>>1;
build(rt<<1,l,mid,opt);
build(rt<<1|1,mid+1,r,opt);
pushup(rt,l,r);
}
void pushdown(int rt,int l,int r){
int mid=l+r>>1;
tag1[rt<<1]=(tag1[rt<<1]+tag1[rt])%MOD,tag1[rt<<1|1]=(tag1[rt<<1|1]+tag1[rt])%MOD;
tag2[rt<<1]=(tag2[rt<<1]+tag2[rt])%MOD,tag2[rt<<1|1]=(tag2[rt<<1|1]+tag2[rt])%MOD;
tr1[rt<<1]=(tr1[rt<<1]+tag1[rt]*pre[mid-l+1]%MOD)%MOD,tr1[rt<<1|1]=(tr1[rt<<1|1]+tag1[rt]*pre[r-mid]%MOD)%MOD;
tr2[rt<<1]=(tr2[rt<<1]+tag2[rt]*pre[mid-l+1]%MOD)%MOD,tr2[rt<<1|1]=(tr2[rt<<1|1]+tag2[rt]*pre[r-mid]%MOD)%MOD;
tag1[rt]=tag2[rt]=0;
}
void update(int rt,int l,int r,int L,int R,long long p,int opt){
if(L<=l && R>=r){
if(!opt) tag1[rt]=(tag1[rt]+p)%MOD,tr1[rt]=(tr1[rt]+pre[r-l+1]*(long long)p%MOD)%MOD;
else tag2[rt]=(tag2[rt]+p)%MOD,tr2[rt]=(tr2[rt]+pre[r-l+1]*(long long)p%MOD)%MOD;
return ;
}
pushdown(rt,l,r);
int mid=l+r>>1;
if(L<=mid){
update(rt<<1,l,mid,L,R,p,opt);
}
if(R>mid){
update(rt<<1|1,mid+1,r,L,R,p,opt);
}
pushup(rt,l,r);
return ;
}
long long query(int rt,int l,int r,int L,int R,int opt){
if(L<=l && R>=r){
if(!opt){
return tr1[rt];
}
else{
return tr2[rt];
}
}
pushdown(rt,l,r);
int mid=l+r>>1;
long long ret=0;
if(L<=mid){
ret=query(rt<<1,l,mid,L,R,opt);
}
if(R>mid){
ret=(ret*qp[max(0,min(r,R)-mid)]%MOD+query(rt<<1|1,mid+1,r,L,R,opt))%MOD;
}
pushup(rt,l,r);
return ret;
}
int check(int x,int mid){
// cout<<query(1,1,n,x-mid,x-1,0)<<" "<<query(1,1,n,n-x-mid+1,n-x,1)<<endl;
if(query(1,1,n,x-mid,x-1,0)==query(1,1,n,n-x-mid+1,n-x,1)){
return 1;
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>q>>k>>b;
k=(k+MOD)%MOD;
b=(b+MOD)%MOD;
prep();
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]=(a[i]+MOD)%MOD;
c[i]=(2*a[i]-(long long)i*k)%MOD;
c[i]=(c[i]+MOD)%MOD;
}
build(1,1,n,0);
build(1,1,n,1);
while(q--){
int opt;
cin>>opt;
if(opt==1){
long long l,r,v;
cin>>l>>r>>v;
v=(v+MOD)%MOD;
update(1,1,n,l,r,(long long)2*v,0);
update(1,1,n,n-r+1,n-l+1,(long long)2*v,1);
}
else{
int x;
cin>>x;
int l=1,r=min(x-1,n-x);
while(l<=r){
int mid=l+r>>1;
if(check(x,mid)){
l=mid+1;
}
else{
r=mid-1;
}
}
cout<<r;
puts("");
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9732kb
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:
1020
result:
wrong answer 1st numbers differ - expected: '1', found: '1020'