ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201833 | #2988. 相似子串 | augury | 100 | 1837ms | 51244kb | C++11 | 2.5kb | 2024-02-07 09:40:56 | 2024-02-07 15:10:10 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int ans=0;bool op=0;char ch=getchar();
while(ch<'0'||'9'<ch){if(ch=='-')op=1;ch=getchar();}
while('0'<=ch&&ch<='9'){ans=(ans<<1)+(ans<<3)+(ch^48);ch=getchar();}
if(op)return -ans;
return ans;
}
const int maxn=1e5+10;
mt19937 rnd(time(0));
int n,q;
int a[maxn];
int val[maxn];
int maxa=0;
map<int,int> mp;
struct node{
int l,r,val;
}tr[maxn*20];
int rt[maxn],cnt;
void newnode(int &p){
tr[++cnt]=tr[p];
p=cnt;
}
void pushup(int p){
tr[p].val=tr[tr[p].l].val+tr[tr[p].r].val;
}
void update(int pos,int s,int t,int &p){
newnode(p);
if(s==t){
tr[p].val+=val[pos];
return;
}
int mid=(s+t)>>1;
if(pos<=mid)update(pos,s,mid,tr[p].l);
else update(pos,mid+1,t,tr[p].r);
pushup(p);
}
int findl(int a,int b,int c,int d,int s,int t){
if(s==t)return tr[b].val-tr[a].val-tr[d].val+tr[c].val;
int mid=(s+t)>>1;
if(tr[tr[b].l].val-tr[tr[a].l].val!=tr[tr[d].l].val-tr[tr[c].l].val){
return findl(tr[a].l,tr[b].l,tr[c].l,tr[d].l,s,mid);
}
else return findl(tr[a].r,tr[b].r,tr[c].r,tr[d].r,mid+1,t);
}
int findr(int a,int b,int c,int d,int s,int t){
if(s==t)return tr[b].val-tr[a].val-tr[d].val+tr[c].val;
int mid=(s+t)>>1;
if(tr[tr[b].r].val-tr[tr[a].r].val!=tr[tr[d].r].val-tr[tr[c].r].val){
return findr(tr[a].r,tr[b].r,tr[c].r,tr[d].r,mid+1,t);
}
else return findr(tr[a].l,tr[b].l,tr[c].l,tr[d].l,s,mid);
}
int sum(int a,int b,int c,int d,int l,int r,int s,int t){
if(l>r)return 0;
if(l<=s&&t<=r)return tr[b].val-tr[a].val+tr[d].val-tr[c].val;
int mid=(s+t)>>1;
int ans=0;
if(l<=mid)ans+=sum(tr[a].l,tr[b].l,tr[c].l,tr[d].l,l,r,s,mid);
if(mid<r)ans+=sum(tr[a].r,tr[b].r,tr[c].r,tr[d].r,l,r,mid+1,t);
return ans;
}
signed main(){
n=read(),q=read();
for(int i=1;i<=n;i++)a[i]=read(),maxa=max(maxa,a[i]);
for(int i=1;i<=maxa;i++)val[i]=rnd();
for(int i=1;i<=maxa;i++)mp[val[i]]=i;
for(int i=1;i<=n;i++){
rt[i]=rt[i-1];
update(a[i],1,maxa,rt[i]);
}
for(int i=1;i<=q;i++){
int c=read(),d=read(),e=read(),f=read();
int ps1=findl(rt[c-1],rt[d],rt[e-1],rt[f],1,maxa);
int ps2=findr(rt[c-1],rt[d],rt[e-1],rt[f],1,maxa);
ps1=abs(ps1),ps2=abs(ps2);
if(!ps1&&!ps2)puts("YES");
else if(!mp.count(ps1)||!mp.count(ps2))puts("NO");
else{
int val1=mp[ps1],val2=mp[ps2];
int tmp=sum(rt[c-1],rt[d],rt[e-1],rt[f],val1+1,val2-1,1,maxa);
if(tmp)puts("NO");
else puts("YES");
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 39ms
memory: 8636kb
input:
1000 1000 40025 48458 97086 78415 76938 71808 52491 96467 81990 89029 88412 76797 44759 80073 43635 ...
output:
YES YES YES YES YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO...
result:
ok 1000 tokens
Test #2:
score: 10
Accepted
time: 37ms
memory: 8636kb
input:
1000 1000 69744 92174 63952 36902 40748 32933 60242 43020 12822 18583 84269 33755 13117 75801 5871 8...
output:
YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YE...
result:
ok 1000 tokens
Test #3:
score: 10
Accepted
time: 51ms
memory: 15400kb
input:
100000 100000 8 4 17 8 4 10 19 3 14 18 11 10 8 2 7 18 2 8 18 17 16 3 18 15 15 16 5 9 20 12 6 11 20 1...
output:
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 N...
result:
ok 100000 tokens
Test #4:
score: 10
Accepted
time: 173ms
memory: 51244kb
input:
100000 100000 1192 1192 45430 45430 44692 44692 46878 46878 68670 68670 69305 69305 80469 80469 2221...
output:
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 N...
result:
ok 100000 tokens
Test #5:
score: 10
Accepted
time: 186ms
memory: 51228kb
input:
100000 100000 64728 33717 46555 82262 17578 99121 39183 29026 36451 3512 24307 55525 60881 71398 220...
output:
YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES NO NO ...
result:
ok 100000 tokens
Test #6:
score: 10
Accepted
time: 167ms
memory: 50156kb
input:
100000 100000 2030 29575 55708 7893 41387 2946 55708 41387 41387 84734 68661 51149 84734 51149 40070...
output:
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 N...
result:
ok 100000 tokens
Test #7:
score: 10
Accepted
time: 327ms
memory: 51220kb
input:
100000 100000 77584 83199 12852 23312 51680 90179 35136 78375 61547 49389 44615 86507 45244 24298 21...
output:
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 ...
result:
ok 100000 tokens
Test #8:
score: 10
Accepted
time: 341ms
memory: 51224kb
input:
100000 100000 48446 18460 31385 83942 29144 78217 71839 76045 45132 62950 10261 80012 69105 88259 18...
output:
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 YES NO...
result:
ok 100000 tokens
Test #9:
score: 10
Accepted
time: 324ms
memory: 51244kb
input:
100000 100000 67258 22476 80140 65110 15276 45289 52581 78244 71886 4975 93295 27696 50915 43339 811...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES NO NO NO NO NO NO NO NO NO NO NO...
result:
ok 100000 tokens
Test #10:
score: 10
Accepted
time: 192ms
memory: 50112kb
input:
100000 100000 93192 79039 80188 16618 93192 16618 93659 79039 28122 14377 93192 79039 59195 70654 36...
output:
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 N...
result:
ok 100000 tokens
Extra Test:
score: 0
Extra Test Passed