QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187769 | #5466. Permutation Compression | Coke | WA | 2ms | 9960kb | C++14 | 1.3kb | 2023-09-24 21:56:07 | 2023-09-24 21:56:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr<<#x<<' '<<x<<endl;
typedef pair<int,int>PII;
typedef long long LL;
constexpr int N=200010,mod=1e9+7;
int a[N],b[N],l[N],pre[N],pos[N];
PII cnt[N];
signed main()
{
//freopen(".in","r",stdin);freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>a[i],pos[a[i]]=i;
a[n+1]=n+1;
set<int>s1,s2;
for(int i=1;i<=m;i++)cin>>b[i],s1.insert(b[i]);
for(int i=1;i<=k;i++)cin>>l[i],s2.insert(l[i]);
set<int>s;
s.insert(0);
s.insert(n+1);
int flag=1;
for(int i=1,j=1;i<=m;i++)
{
while(j<=n&&a[j]!=b[i])j++;
if(j>n)
{
flag=0;
break;
}
}
if(flag==0)
{
cout<<"NO"<<endl;
continue;
}
for(int i=n;i>=1;i--)
{
auto p=s.lower_bound(pos[i]);
cnt[i].first=*p-*prev(p)-1;
cnt[i].second=i;
s.insert(pos[i]);
}
sort(cnt+1,cnt+n+1);
int f=1;
for(int i=n;i>=1;i--)
{
if(s1.count(cnt[i].second))continue;
auto it=s2.upper_bound(cnt[i].first);
if(it==s2.begin())
{
f=0;
break;
}
it--;
s2.erase(it);
}
if(f)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9676kb
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: 9960kb
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 NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES NO YES YES YES YES YES NO NO YES YES YES NO NO NO NO YES NO NO YES YES YES YES YES NO YES NO YES NO YES NO NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES ...
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'