QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548195 | #5466. Permutation Compression | ucup-team3294 | WA | 0ms | 3600kb | C++20 | 2.8kb | 2024-09-05 16:20:05 | 2024-09-05 16:20:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
const int N=2e5+10;
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;
}
if(u==45)
{
cout<<n<<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());
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);
int T;
cin>>T;
for(int i=1;i<=T;i++)
{
solve(i);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
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: 3600kb
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 3 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 YES...
result:
wrong answer 45th lines differ - expected: 'NO', found: '3'