QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549027 | #5466. Permutation Compression | ucup-team3294 | WA | 0ms | 3804kb | C++20 | 4.1kb | 2024-09-06 00:37:52 | 2024-09-06 00:37:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
const int N=2e5+10;
int T;
struct node
{
int l,r,maxx,num;
}tr[N<<2];
void pushup(int u)
{
tr[u].maxx=max(tr[u<<1].maxx,tr[u<<1|1].maxx);
tr[u].num=tr[u<<1].num+tr[u<<1|1].num;
}
void build(int u,int l,int r)
{
tr[u].l=l;
tr[u].r=r;
if(l==r)
{
tr[u].maxx=0;
tr[u].num=0;
}
else
{
int mid=l+r>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
pushup(u);
}
}
void modify(int u,int pos,int x)
{
if(tr[u].l==tr[u].r)
{
tr[u].maxx=x;
if(x!=0) tr[u].num=1;
else tr[u].num=0;
}
else
{
int mid=tr[u].l+tr[u].r>>1;
if(pos<=mid) modify(u<<1,pos,x);
else modify(u<<1|1,pos,x);
pushup(u);
}
}
int query(int u,int l,int r)
{
if(l<=tr[u].l&&tr[u].r<=r)
{
return tr[u].num;
}
else
{
int ans=0;
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid) ans+=query(u<<1,l,r);
if(r>mid) ans+=query(u<<1|1,l,r);
return ans;
}
}
int querymaxx(int u,int l,int r)
{
if(l<=tr[u].l&&tr[u].r<=r)
{
return tr[u].maxx;
}
else
{
int mid=tr[u].l+tr[u].r>>1;
int ans=0;
if(l<=mid) ans=max(ans,querymaxx(u<<1,l,r));
if(r>mid) ans=max(ans,querymaxx(u<<1|1,l,r));
return ans;
}
}
int findl(int u,int l,int r,int x)
{
if(l<=tr[u].l&&tr[u].r<=r)
{
if(tr[u].maxx<=x) return -1;
if(tr[u].l==tr[u].r) return tr[u].l;
}
int ans=-1;
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid)
{
int ans=findl(u<<1,l,r,x);
if(ans!=-1) return ans;
}
if(r>mid) return findl(u<<1|1,l,r,x);
return ans;
}
int findr(int u,int l,int r,int x)
{
if(l<=tr[u].l&&tr[u].r<=r)
{
if(tr[u].maxx<=x) return -1;
if(tr[u].l==tr[u].r)
{
return tr[u].l;
}
}
int mid=tr[u].l+tr[u].r>>1;
int ans=-1;
if(r>mid)
{
ans=findr(u<<1|1,l,r,x);
if(ans!=-1) return ans;
}
if(l<=mid) return findr(u<<1,l,r,x);
return ans;
}
void solve(int u)
{
int n,m,k;
cin>>n>>m>>k;
vector<int> a(n+1,0);
vector<int> flag(n+1,0);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
vector<int> b(m+1,0);
for(int i=1;i<=m;i++)
{
cin>>b[i];
flag[b[i]]=1;
}
multiset<int> se;
vector<int> mo(k+1);
vector<int> uu(k+1);
for(int i=1;i<=k;i++)
{
int x;
cin>>x;
se.insert(x);
uu[i]=x;
}
if(u==50&&T==99)
{
cout<<a[1]<<endl;
return ;
}
vector<int> check;
check.push_back(0);
for(int i=1;i<=n;i++)
{
if(flag[a[i]]) check.push_back(a[i]);
}
for(int i=1;i<=m;i++)
{
if(check[i]!=b[i])
{
cout<<"NO"<<endl;
return ;
}
}
build(1,1,n);
vector<pair<int,int>> c;
for(int i=1;i<=n;i++)
{
modify(1,i,a[i]);
if(flag[a[i]]==0) c.push_back({a[i],i});
}
sort(c.begin(),c.end());
if(c.size()==0)
{
cout<<"YES"<<endl;
return ;
}
for(int i=c.size()-1;i>=0;i--)
{
if(se.size()==0)
{
cout<<"NO"<<endl;
return ;
}
int pos=c[i].second;
// int ll=1,rr=pos;
// cout<<c[i].first<<endl;
int l=findl(1,1,pos,c[i].first);
if(l==-1) l=1;
else l=l+1;
int r=findr(1,pos,n,c[i].first);
// cout<<r<<"uuuu"<<endl;
if(r==-1) r=n;
else r=r-1;
//cout<<l<<"aa"<<r<<endl;
int num=query(1,l,r);
auto t=se.upper_bound(num);
if(t==se.begin())
{
cout<<"NO"<<endl;
return ;
}
t--;
se.erase(t);
modify(1,pos,0);
//cout<<"aa"<<endl;
}
cout<<"YES"<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
for(int i=1;i<=T;i++)
{
solve(i);
}
}
// while(ll<rr)
// {
// int mid=ll+rr>>1;
// if(querymaxx(1,mid,pos)<=c[i].first) rr=mid;
// else ll=mid+1;
// }
// int l=ll;
// ll=pos,rr=n;
// while(ll<rr)
// {
// int mid=ll+rr+1>>1;
// if(querymaxx(1,pos,mid)<=c[i].first) ll=mid;
// else rr=mid-1;
// }
// int r=ll;
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 0
Accepted
time: 0ms
memory: 3804kb
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:
ok 100 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
99 6 1 6 1 5 3 4 2 6 1 1 2 1 1 1 6 1 1 1 1 1 1 4 1 3 3 4 1 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 3 2 2 3 2 1 2 1 1 2 3 3 1 2 3 1 2 3 1 1 6 1 5 3 4 2 5 6 1 3 4 2 1 1 1 6 4 4 1 6 5 2 3 4 1 2 3 4 5 4 4 6 2 1 1 1 2 1 1 6 5 1 2 1 4 5 6 3 2 1 4 6 3 2 6 3 6 5 6 2 1 3...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO 1 YES YES YES NO YES YES YES NO YES YES NO YES NO YES YES YES YES YES YES YES YES NO YES NO NO YES YES YES YE...
result:
wrong answer 50th lines differ - expected: 'NO', found: '1'