QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133685 | #4940. Token Distance | whsyhyyh# | WA | 1ms | 23972kb | C++14 | 3.1kb | 2023-08-02 12:55:58 | 2023-08-02 12:56:04 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 200010
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
struct qry {
int opt,x,y;
}q[N];
int n,Q,a[N],m;
int b[N],tot;
unordered_map<int,int>mp;
set<int>S[N];
set<int>::iterator it;
struct node {
int d,mx,mn,s1,s0;
};
struct Seg {
int d[N<<2],mx[N<<2],mn[N<<2],Same[N<<2][2];
void update(int p) {
mx[p]=max(mx[p<<1],mx[p<<1|1]);
mn[p]=min(mn[p<<1],mn[p<<1|1]);
d[p]=__gcd(d[p<<1],d[p<<1|1]);
Same[p][1]=min(Same[p<<1][1],Same[p<<1|1][1]);
Same[p][0]=max(Same[p<<1][0],Same[p<<1][0]);
}
void init(int p,int l) {
mn[p]=mx[p]=a[l],d[p]=abs(a[l]-a[l+1]);
int tmp=mp[a[l]];
it=S[tmp].upper_bound(l);
if(it!=S[tmp].end()) Same[p][1]=*it;else Same[p][1]=inf;
it--;if(it!=S[tmp].begin()) it--,Same[p][0]=*it;else Same[p][0]=0;
}
void build(int p,int l,int r) {
if(l==r) {
init(p,l);
return ;
}
int mid=l+r>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
update(p);
}
void modify(int p,int l,int r,int x) {
if(l==r) {
init(p,l);
return ;
}
int mid=l+r>>1;
if(x<=mid) modify(p<<1,l,mid,x);
else modify(p<<1|1,mid+1,r,x);
update(p);
}
node gets(int p,int l,int r,int L,int R) {
if(l>=L&&r<=R) return (node) {d[p],mx[p],mn[p],Same[p][1],Same[p][0]};
int mid=l+r>>1;
if(R<=mid) return gets(p<<1,l,mid,L,R);
if(L>mid) return gets(p<<1|1,mid+1,r,L,R);
node A=gets(p<<1,l,mid,L,R),B=gets(p<<1|1,mid+1,r,L,R);
return (node) {__gcd(A.d,B.d),max(A.mx,B.mx),min(A.mn,B.mn),min(A.s1,B.s1),max(A.s0,B.s0)};
}
}T;
bool check(int l,int r) {
if(r-l+1<=2) return 1;
node tmp=T.gets(1,1,n,l,r);
if(tmp.mn==tmp.mx) return 1;
if(tmp.s1<=r||tmp.s0>=l) return 0;
if((tmp.mx-tmp.mn)%(r-l)) return 0;
// int d=(tmp.mx-tmp.mn)/(r-l);
// return T.gets(1,1,n,l,r-1).d%d==0;
}
int main() {
n=rd(),Q=rd();
rep(i,1,n) a[i]=rd(),b[++m]=a[i];
rep(i,1,Q) {
q[i].opt=rd(),q[i].x=rd(),q[i].y=rd();
if(q[i].opt==1) b[++m]=q[i].y;
}
b[0]=-1;sort(b+1,b+m+1);rep(i,1,m) if(b[i]!=b[i-1]) mp[b[i]]=++tot;
rep(i,1,n) S[mp[a[i]]].insert(i);
T.build(1,1,n);
rep(i,1,Q) {
if(q[i].opt==1) {
int tmp=mp[a[q[i].x]];
S[tmp].erase(q[i].x);
it=S[tmp].upper_bound(q[i].x);
if(it!=S[tmp].end()) T.modify(1,1,n,*it);
if(it!=S[tmp].begin()) it--,T.modify(1,1,n,*it);
a[q[i].x]=q[i].y;
tmp=mp[a[q[i].x]];
S[tmp].insert(q[i].x);
it=S[tmp].upper_bound(q[i].x);
if(it!=S[tmp].end()) T.modify(1,1,n,*it);
it--;if(it!=S[tmp].begin()) it--,T.modify(1,1,n,*it);
T.modify(1,1,n,q[i].x);
}
else {
if(check(q[i].x,q[i].y)) puts("YES");
else puts("NO");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 23972kb
input:
5 7 1 1 1 10 1 2 1 3 2 1 5 1 5 4 1 3 7 2 2 4 2 2 5 2 4 5
output:
YES NO NO NO YES
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'