QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187773 | #5466. Permutation Compression | Coke | WA | 1ms | 3556kb | C++14 | 1.6kb | 2023-09-24 22:09:02 | 2023-09-24 22:09:02 |
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];
struct BIT{
vector<int>tr;
BIT (){};
BIT (int n):tr(n){};
int lowbit(int x)
{
return x&-x;
}
void add(int x,int va)
{
for(int i=x;i<tr.size();i+=lowbit(i))tr[i]+=va;
}
int sum(int x)
{
int res=0;
for(int i=x;i;i-=lowbit(i))res+=tr[i];
return res;
}
};
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;
BIT v(n+1);
for(int i=1;i<=n;i++)cin>>a[i],pos[a[i]]=i,v.add(i,1);
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;
}
int f=1;
for(int i=n;i>=1;i--)
{
if(s1.count(i))
{
s.insert(pos[i]);
continue;
}
auto p=s.lower_bound(pos[i]);
int l=*prev(p),r=*p;
int len=v.sum(r-1)-v.sum(l);
auto it=s2.upper_bound(len);
if(it==s2.begin())
{
f=0;
break;
}
it--;
v.add(pos[i],-1);
s2.erase(it);
s.insert(pos[i]);
}
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: 3556kb
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: 0ms
memory: 3452kb
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'