QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133702 | #4940. Token Distance | whsyhyyh# | WA | 72ms | 38804kb | C++14 | 3.1kb | 2023-08-02 13:07:55 | 2023-08-02 13:07:57 |
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;
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 24000kb
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 YES YES
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 21992kb
input:
2 1 0 1000000000 2 1 2
output:
YES
result:
ok single line: 'YES'
Test #3:
score: 0
Accepted
time: 16ms
memory: 33772kb
input:
81473 13549 972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...
output:
YES YES YES YES NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES NO YES NO YES YES YES NO YES YES YES YES YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES NO YES YES YES YES YES YES YES YES YES NO YES NO YES NO YES YES YES YES Y...
result:
ok 4517 lines
Test #4:
score: 0
Accepted
time: 26ms
memory: 35816kb
input:
81473 13549 994993061 993089286 973546017 983608065 980300695 994305454 992559601 974765838 987574661 988923180 987601637 991357764 981678157 994388630 987066613 976087381 985770922 989296067 975698758 977548300 992236732 978102432 983875296 979745439 977111907 992622264 988921213 987697458 99145442...
output:
NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES...
result:
ok 4517 lines
Test #5:
score: 0
Accepted
time: 16ms
memory: 35796kb
input:
81473 13549 972586964 972586683 972587526 972587245 972588088 972587807 972588650 972588369 972589212 972588931 972589774 972589493 972590336 972590055 972590898 972590617 972591460 972591179 972592022 972591741 972592584 972592303 972593146 972592865 972593708 972593427 972594270 972593989 97259483...
output:
NO NO YES YES NO NO YES NO NO YES NO YES NO NO NO NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES YES NO NO NO YES NO NO NO YES NO YES NO YES NO NO NO NO NO NO NO YES NO YES NO NO YES NO NO YES NO NO NO NO NO NO YES YES NO NO NO NO YES NO NO NO NO NO NO YES...
result:
ok 13549 lines
Test #6:
score: 0
Accepted
time: 29ms
memory: 32924kb
input:
81473 13549 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
ok 13549 lines
Test #7:
score: 0
Accepted
time: 43ms
memory: 32928kb
input:
81473 13549 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...
output:
YES NO YES NO YES YES NO YES NO YES YES YES NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO YES NO NO NO YES NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO YES NO NO NO NO YES NO NO NO NO NO...
result:
ok 6727 lines
Test #8:
score: 0
Accepted
time: 69ms
memory: 38804kb
input:
96888 91338 0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
ok 91338 lines
Test #9:
score: 0
Accepted
time: 57ms
memory: 37548kb
input:
96888 91338 0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...
output:
NO YES YES NO NO YES YES NO YES YES YES YES YES NO YES NO YES NO NO NO YES YES YES NO NO YES YES NO YES NO YES YES NO NO YES YES NO NO NO NO YES YES NO YES YES NO YES NO YES YES YES NO YES YES NO NO YES YES YES NO NO NO NO YES NO YES YES YES YES NO YES NO YES YES NO YES NO YES YES YES YES YES YES YE...
result:
ok 91338 lines
Test #10:
score: 0
Accepted
time: 71ms
memory: 38608kb
input:
96888 91338 0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...
output:
YES YES NO NO NO NO YES NO YES YES NO NO YES NO NO NO NO YES NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO N...
result:
ok 45670 lines
Test #11:
score: 0
Accepted
time: 69ms
memory: 37520kb
input:
96888 91338 148622400 313851289 796564459 844340368 558593162 622118917 828177682 162586713 809187042 120384144 635536217 253999810 681392420 868894027 212922230 762102640 996956995 352833706 345175524 294127858 22179829 707700649 122520591 837858780 906906270 596853109 3416251 593901303 130684502 8...
output:
NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES...
result:
ok 45670 lines
Test #12:
score: 0
Accepted
time: 72ms
memory: 38184kb
input:
96888 91338 0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...
output:
YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES NO YES YES YES YES YES YES YES YES YES NO YES NO YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES YES YES YES YES YE...
result:
ok 45670 lines
Test #13:
score: 0
Accepted
time: 29ms
memory: 34788kb
input:
81473 13549 972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
ok 13549 lines
Test #14:
score: -100
Wrong Answer
time: 69ms
memory: 37336kb
input:
96888 91338 595841651 917330480 207421137 35297820 388823033 754743767 175477642 575292540 427299721 685520820 420849096 990712790 335515068 880143917 298720703 665301981 644711586 983560337 804026542 699918615 863609675 666912057 857974409 277769073 133161542 363784287 536671358 866138320 98617155 ...
output:
NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES...
result:
wrong answer 39481st lines differ - expected: 'NO', found: 'YES'