QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89014 | #5466. Permutation Compression | shihoghmean | WA | 2ms | 3460kb | C++14 | 3.1kb | 2023-03-18 11:17:28 | 2023-03-18 11:17:30 |
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];
multiset<int> st;
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 R=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,R=mid;
}
l=1;
r=now-1;
int L=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,L=mid;
}
// printf("%d %d\n",L,R);
return querynum(1,1,n,L,R);
}
signed main(){
int tt=read();
while(tt--){
n=read();m=read();
k=read();
st.clear();
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) {
int x=read();
st.insert(x);
}
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);
auto it=(st.upper_bound(x));
if((*st.begin())>x){
fl=1;
pn;
break;
}
st.erase(*(it--));
}
}
if(fl) continue;
py;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
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: -100
Wrong Answer
time: 2ms
memory: 3348kb
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 YES NO YES YES NO NO YES YES YES YES NO 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 Y...
result:
wrong answer 40th lines differ - expected: 'NO', found: 'YES'