QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592257#5466. Permutation CompressionBaiyu0123#WA 1ms5700kbC++201.7kb2024-09-26 21:36:062024-09-26 21:36:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 21:36:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2024-09-26 21:36:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100,lim=1e6;
int sum[maxn<<2],n;
int a[maxn],p[maxn],bl[maxn];
set<int> s;
multiset<int> b; 
void update(int w) {
	sum[w]=sum[w<<1]+sum[w<<1|1]; 
}
void build(int l,int r,int w) {
	sum[w]=r-l+1;
	if (l==r) return ;
	int mid=(l+r)>>1;
	build(l,mid,w<<1);
	build(mid+1,r,w<<1|1);
}
void modify(int q,int l,int r,int w) {
	if (q==l&&q==r) {
		sum[w]=0;
		return ;
	}
	int mid=(l+r)>>1;
	if (q<=mid) modify(q,l,mid,w<<1);
	if (q>=mid+1) modify(q,mid+1,r,w<<1|1);
	update(w);
}
int query(int ql,int qr,int l,int r,int w) {
	if (ql<=l&&r<=qr) {
		return sum[w];
	}
	int mid=(l+r)>>1,ret=0;
	if (ql<=mid) ret+=query(ql,qr,l,mid,w<<1);
	if (qr>=mid+1) ret+=query(ql,qr,mid+1,r,w<<1|1);
	return ret;
}
bool cmp(const int &x,const int &y) {
	return x>y;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while (T--) {
		int n,m,k,ans=1;
		cin>>n>>m>>k;
		build(1,n,1);
		for (int i=1;i<=n;i++) cin>>p[i],a[p[i]]=i;
		for (int i=1;i<=m;i++) {
			int x;cin>>x;
			bl[x]=1;
		}
		for (int i=1;i<=k;i++) {
			int x;cin>>x;
			b.insert(x);
		}
		s.insert(0);s.insert(n+1);
		b.insert(0);
		for (int i=n;i>=1;i--) {
			int w=a[i];
			if (bl[i]) s.insert(w);
			else {
				auto it=s.lower_bound(w);
				int r=*it;
				it--;
				int l=*it;
				int ret=query(l+1,r-1,1,n,1);
				auto itb=b.lower_bound(ret+1);
				itb--;
				int len=*itb;
				if (len==0) {
					ans=0;
					break;
				}
				b.erase(itb);
				modify(w,1,n,1);
			}
		}
		if (ans) cout<<"YES\n";
		else cout<<"NO\n";
		s.clear();b.clear();
		for (int i=1;i<=n;i++) bl[i]=0;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

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: 1ms
memory: 5700kb

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
YES
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
Y...

result:

wrong answer 45th lines differ - expected: 'NO', found: 'YES'