QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291441 | #5466. Permutation Compression | ushg8877# | WA | 2ms | 10576kb | C++14 | 1.8kb | 2023-12-26 16:56:49 | 2023-12-26 16:56:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=2e5+5;
int n,m,k;
int a[MAXN],pa[MAXN],lg[MAXN];
bool flag[MAXN],ban[MAXN];
multiset<int> se;
struct ST_table{
int a[20][MAXN];
void init(){
for(int i=1;i<=n;i++) a[0][i]=0;
}
void build(){
for(int i=1;i<20;i++)
for(int j=1;j+(1<<i)-1<=n;j++)
a[i][j]=max(a[i-1][j],a[i-1][j+(1<<i-1)]);
}
int ask(int l,int r){
int k=lg[r-l+1];
return max(a[k][l],a[k][r-(1<<k)+1]);
}
}st;
struct BIT{
int a[MAXN];
void init(){for(int i=1;i<=n;i++)a[i]=0;}
void add(int x,int d){while(x<=n)a[x]+=d,x+=(x&-x);}
int ask(int x){int r=0;while(x)r+=a[x],x-=(x&-x);return r;}
}T;
void solve(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>a[i],pa[a[i]]=i,flag[i]=false;
bool tmp=false;
for(int i=1,x,lst=0;i<=m;i++){
cin>>x,flag[x]=true;ban[pa[x]]=true;
if(pa[x]<lst) tmp=true;lst=pa[x];
}
se.clear();
for(int i=1;i<=k;i++){
int x;cin>>x;se.insert(x);
}
if(tmp){cout<<"NO"<<endl;return;}
T.init();st.init();
for(int i=1;i<=n;i++) if(ban[i]) st.a[0][i]=a[i];
st.build();
for(int i=1;i<=n;i++) T.add(i,1);
// cout<<st.ask(1,2)<<endl;
for(int i=n;i>=1;i--) if(!flag[i]){
int p=pa[i];
int l=1,r=p,mid,L,R;
while(l<r){
mid=l+r>>1;
if(st.ask(mid,p)>i) l=mid+1;
else r=mid;
}
L=l;
l=p,r=n;
while(l<r){
mid=l+r+1>>1;
if(st.ask(p,mid)>i) r=mid-1;
else l=mid;
}
R=r;
// cout<<L<<' '<<R<<' '<<p<<endl;
int x=T.ask(R)-T.ask(L-1);
if(se.empty()){cout<<"NO"<<endl;return;}
auto it=se.upper_bound(x);
if(it==se.begin()){cout<<"NO"<<endl;return;}
--it;se.erase(it);
T.add(p,-1);
}
cout<<"YES"<<endl;
}
int main(){
ios::sync_with_stdio(false);
for(int i=2;i<MAXN;i++) lg[i]=lg[i>>1]+1;
int _;cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7756kb
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: 10576kb
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:
wrong answer 82nd lines differ - expected: 'YES', found: 'NO'