QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245601 | #5466. Permutation Compression | joelgun14 | WA | 0ms | 3468kb | C++14 | 1.4kb | 2023-11-10 05:09:33 | 2023-11-10 05:09:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
const int inf = 1e9;
int n,m,k,a[N],pos[N],b[N],l[N],need[N];
bool del[N];
int c[N];
int lowbit(int x) {return x&-x;}
void add(int x,int k)
{
while(x<=n)
{
c[x]+=k;
x+=lowbit(x);
}
}
int query(int x)
{
int ans=0;
while(x)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
int query(int x,int y) {return query(y)-query(x-1);}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;cin>>t;
while(t--)
{
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>a[i],pos[a[i]]=i;
for(int i=1;i<=m;i++) cin>>b[i];
for(int i=1;i<=k;i++) cin>>l[i];
if(n-m>k)
{
cout<<"tidak"<<'\n';
continue;
}
sort(l+1,l+k+1);
for(int i=1;i<=n;i++) c[i]=0,del[i]=1;
for(int i=1;i<=m;i++) del[b[i]]=0;
set<int> s;
s.insert(0),s.insert(n+1);
int p=0;
for(int i=n;i;i--)
if(del[i])
{
auto it=s.lower_bound(pos[i]);
int l=*(prev(it)),r=*it;
need[++p]=r-l-1-query(l+1,r-1);
add(pos[i],1);
}
else s.insert(pos[i]);
bool ok=1;
sort(need+1,need+p+1);
for(int i=1;i<=p;i++)
if(need[i]<l[i]) ok=0;
cout<<(ok?"ya":"tidak")<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3468kb
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:
ya ya tidak
result:
wrong answer 1st lines differ - expected: 'YES', found: 'ya'