QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89006 | #5466. Permutation Compression | shihoghmean | WA | 11ms | 3436kb | C++14 | 3.1kb | 2023-03-18 10:54:56 | 2023-03-18 10:54:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define py puts("YES")
#define pn puts("NO")
#define pt puts("")
#define pb push_back
#define wt(x) write(x),puts("")
#define tx printf("fds")
#define mp make_pair
#define fi first
#define se second
inline int read(){
int x=0,k=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') k=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+ch-48;
ch=getchar();
}
return x*k;
}
void write(int x){
if(x<0){
x=-x;
putchar('-');
}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int power(int x,int y,int mod){
int num=1;
while(y){
if(y&1) num=(num*x)%mod;
x=x*x%mod;
y>>=1;
}
return num;
}
int mul(int x,int y,int mod){
int num=0;
while(y){
if(y&1) num=(num+x)%mod;
x=(x+x)%mod;
y>>=1;
}
return num;
}
const int N=1e6+7,mod=998244353;
int n,m,tot,cnt,ans,k;
int a[N],b[N],c[N],d[N],z[N];
struct tree{
int max,num;
}t[N];
void pu(int id){
t[id].max=max(t[id<<1].max,t[id<<1|1].max);
t[id].num=t[id<<1].num+t[id<<1|1].num;
}
void build(int id,int l,int r){
if(l==r){
t[id].max=a[l];
t[id].num=1;
return ;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
pu(id);
}
void update(int id,int l,int r,int x){
if(l==r){
t[id].max=0;
t[id].num=0;
return ;
}
int mid=(l+r)>>1;
if(x<=mid) update(id<<1,l,mid,x);
else update(id<<1|1,mid+1,r,x);
pu(id);
}
int querymax(int id,int l,int r,int L,int R){
if(L<=l&&r<=R){
return t[id].max;
}
int mid=(l+r)>>1;
int p=0;
if(L<=mid) p=max(p,querymax(id<<1,l,mid,L,R));
if(mid<R) p=max(p,querymax(id<<1|1,mid+1,r,L,R));
pu(id);
return p;
}
int querynum(int id,int l,int r,int L,int R){
if(L<=l&&r<=R){
return t[id].num;
}
int mid=(l+r)>>1;
int p=0;
if(L<=mid) p+=querynum(id<<1,l,mid,L,R);
if(mid<R) p+=querynum(id<<1|1,mid+1,r,L,R);
pu(id);
return p;
}
int get(int x){
int now=d[x];
int l=now+1,r=n;
int L=now;
while(l<=r){
int mid=(l+r)>>1;
if(querymax(1,1,n,now+1,mid)>x) r=mid-1;
else l=mid+1,L=mid;
}
l=1;
r=now-1;
int R=now;
while(l<=r){
int mid=(l+r)>>1;
if(querymax(1,1,n,mid,now-1)>x) l=mid+1;
else r=mid-1,R=mid;
}
return querynum(1,1,n,R,L);
}
signed main(){
int tt=read();
while(tt--){
n=read();m=read();
k=read();
fo(i,1,n) b[i]=1;
fo(i,1,n) a[i]=read(),d[a[i]]=i;
fo(i,1,m) z[i]=read(),b[z[i]]=0;
fo(i,1,k) c[i]=read();
sort(c+1,c+k+1);
build(1,1,n);
int now=n-m,fl=0;
int p=1;
if(now>k){
fl=1;
pn;
continue;
}
fo(i,1,m){
while(a[p]!=z[i]&&p<=n) p++;
if(p>n){
fl=1;
pn;
break;
}
}
if(fl) continue;
fr(i,n,1){
if(b[i]){
int x=get(i);
if(now<=0){
fl=1;
pn;
break;
}
if(x>=c[now]){
now--;
update(1,1,n,d[i]);
}
else{
fl=1;
pn;
break;
}
}
}
if(fl) continue;
py;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3404kb
input:
3 5 2 3 5 1 3 2 4 5 2 1 2 4 5 5 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 2 2 3 1 2 3 2 2 3
output:
YES YES NO
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3288kb
input:
100 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1 1 2 1 2 6 1 5 3 4 2 5 6 1 3 5 2 1 1 1 6 1 6 2 1 3 6 4 5 1 4 1 2 2 1 4 3 3 2 2 1 3 2 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 4 4 3 2 1 3 4 2 1 3 4 4 3 1 1 1 1 1 1 1 6 5 1 6 2 5 4 3 1 6 2 4 3 1 4 1 1 1 1 1 1 6 5 3 3 6 1 4 5 2 3 6 1 4 2 3 3 4 4 3 4 3 4 ...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES NO NO NO YES YES NO NO YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES YES YE...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
99 6 1 6 1 5 3 4 2 6 1 1 2 1 1 1 6 1 1 1 1 1 1 4 1 3 3 4 1 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 3 2 2 3 2 1 2 1 1 2 3 3 1 2 3 1 2 3 1 1 6 1 5 3 4 2 5 6 1 3 4 2 1 1 1 6 4 4 1 6 5 2 3 4 1 2 3 4 5 4 4 6 2 1 1 1 2 1 1 6 5 1 2 1 4 5 6 3 2 1 4 6 3 2 6 3 6 5 6 2 1 3...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO NO YES YES YES NO YES YES YES NO YES YES NO YES NO YES NO YES YES YES YES YES YES NO YES NO NO YES YES YES YE...
result:
ok 99 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
98 6 1 6 6 1 4 5 2 3 3 1 2 2 1 1 6 4 3 2 2 3 4 1 2 1 3 3 4 1 1 1 1 1 1 6 1 6 6 4 3 1 2 5 1 3 1 3 1 1 5 1 1 1 1 1 1 6 4 4 3 4 1 2 5 6 3 4 1 2 2 4 3 1 6 5 1 4 5 3 6 1 2 4 5 3 1 2 6 1 1 1 1 1 1 5 1 4 1 3 2 4 5 1 5 3 4 4 6 3 4 1 4 2 3 6 5 1 2 5 5 4 6 5 4 1 3 2 1 4 3 2 1 1 1 1 1 1 1 1 1 6 3 5 5 1 3 6 4 2...
output:
YES NO YES YES YES YES YES YES NO NO YES YES NO YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES NO YES YES YES YES YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES NO Y...
result:
ok 98 lines
Test #5:
score: 0
Accepted
time: 11ms
memory: 3324kb
input:
60000 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 2 3 1 2 1 2 3 3 1 1 2 3 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 2 3 2 1 3 2 1 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 1 1 1 1 3 1 3 2 3 1 1 2 3 2 3 3 2 2 3 1 2 3 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 3 3 2 1 2 1 1 2 1 3 2 2 1 3 2 3 2 3 ...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES NO 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 NO 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 60000 lines
Test #6:
score: -100
Wrong Answer
time: 3ms
memory: 3256kb
input:
50000 1 1 1 1 1 1 4 3 4 1 2 3 4 1 2 3 2 3 4 4 1 1 1 1 1 1 3 2 1 3 1 2 1 2 3 4 1 4 2 1 4 3 2 4 4 3 4 3 1 2 1 2 3 2 3 3 4 1 3 4 2 1 3 1 3 2 4 4 4 2 4 1 2 3 4 1 2 3 3 4 3 1 2 2 1 3 3 1 3 4 2 2 4 3 1 2 3 1 2 1 1 1 1 1 1 1 4 3 1 1 2 3 4 1 2 4 4 4 1 4 4 3 2 1 4 2 1 1 2 3 3 1 2 1 3 2 1 3 1 4 3 2 1 3 2 4 1 ...
output:
YES YES YES YES NO NO YES YES NO YES YES NO 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 NO YES NO YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES Y...
result:
wrong answer 4857th lines differ - expected: 'YES', found: 'NO'