QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548230 | #5466. Permutation Compression | ucup-team3294 | WA | 1ms | 3820kb | C++20 | 3.2kb | 2024-09-05 16:30:08 | 2024-09-05 16:30:09 |
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;
}
}
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);
for(int i=1;i<=k;i++)
{
int x;
cin>>x;
se.insert(x);
//mo[i]=x;
}
// string s;
// for(int i=1;i<=n;i++)
// {
// s+=a[i]-'0';
// }
if(u==23&&T==99)
{
cout<<a[4]<<endl;
return ;
}
int idx=0;
for(int i=1;i<=n;i++)
{
if(flag[a[i]])
{
if(a[i]!=b[++idx])
{
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 ;
}
//cout<<c[i].first<<"aa"<<endl;
int pos=c[i].second;
int ll=1,rr=pos;
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,mid,n)<=c[i].first) ll=mid;
else rr=mid-1;
}
int r=ll;
int num=query(1,l,r);
auto t=se.upper_bound(num);
if(t==se.begin())
{
cout<<"NO"<<endl;
return ;
}
t--;
// cout<<*t<<endl;
se.erase(t);
modify(1,pos,0);
//cout<<se.count(1)<<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);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 1ms
memory: 3504kb
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: 3820kb
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 5 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 NO YES YES YES NO YES YES YES NO YES YES NO YES NO YES NO YES YES YES YES YES YES NO YES NO NO YES YES YES YES ...
result:
wrong answer 23rd lines differ - expected: 'YES', found: '5'