QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89017#5466. Permutation CompressionshihoghmeanWA 2ms3316kbC++143.1kb2023-03-18 11:25:132023-03-18 11:25:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-18 11:25:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3316kb
  • [2023-03-18 11:25:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define py puts("YES")
#define pn puts("NO")
#define pt puts("")
#define pb push_back
#define wt(x) write(x),puts("")
#define tx printf("fds")
#define mp make_pair
#define fi first
#define se second
inline int read(){
	int x=0,k=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') k=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+ch-48;
		ch=getchar();
	}
	return x*k;
}
void write(int x){
	if(x<0){
		x=-x;
		putchar('-');
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
int power(int x,int y,int mod){
	int num=1;
	while(y){
		if(y&1) num=(num*x)%mod;
		x=x*x%mod;
		y>>=1;
	}
	return num;
}
int mul(int x,int y,int mod){
	int num=0;
	while(y){
		if(y&1) num=(num+x)%mod;
		x=(x+x)%mod;
		y>>=1;
	}
	return num;
}
const int N=1e6+7,mod=998244353;
int n,m,tot,cnt,ans,k;
int a[N],b[N],c[N],d[N],z[N];
multiset<int> st;
struct tree{
	int max,num;
}t[N];
void pu(int id){
	t[id].max=max(t[id<<1].max,t[id<<1|1].max);
	t[id].num=t[id<<1].num+t[id<<1|1].num;
}
void build(int id,int l,int r){
	if(l==r){
		t[id].max=a[l];
		t[id].num=1;
		return ;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	pu(id);
}
void update(int id,int l,int r,int x){
	if(l==r){
		t[id].max=0;
		t[id].num=0;
		return ;
	}
	int mid=(l+r)>>1;
	if(x<=mid) update(id<<1,l,mid,x);
	else update(id<<1|1,mid+1,r,x);
	pu(id);
}
int querymax(int id,int l,int r,int L,int R){
	if(L<=l&&r<=R){
		return t[id].max;
	}
	int mid=(l+r)>>1;
	int p=0;
	if(L<=mid) p=max(p,querymax(id<<1,l,mid,L,R));
	if(mid<R) p=max(p,querymax(id<<1|1,mid+1,r,L,R));
	pu(id);
	return p;
}
int querynum(int id,int l,int r,int L,int R){
	if(L<=l&&r<=R){
		return t[id].num;
	}
	int mid=(l+r)>>1;
	int p=0;
	if(L<=mid) p+=querynum(id<<1,l,mid,L,R);
	if(mid<R) p+=querynum(id<<1|1,mid+1,r,L,R);
	pu(id);
	return p;
}
int get(int x){
	int now=d[x];
	int l=now+1,r=n;
	int R=now;
	while(l<=r){
		int mid=(l+r)>>1;
		if(querymax(1,1,n,now+1,mid)>x) r=mid-1;
		else l=mid+1,R=mid;
	}
	l=1;
	r=now-1;
	int L=now;
	while(l<=r){
		int mid=(l+r)>>1;
		if(querymax(1,1,n,mid,now-1)>x) l=mid+1;
		else r=mid-1,L=mid;
	}
	// printf("%d %d\n",L,R);
	return querynum(1,1,n,L,R);
}
signed main(){
	int tt=read();
	while(tt--){
		n=read();m=read();
		k=read();
		st.clear();
		fo(i,1,n) b[i]=1;
		fo(i,1,n) a[i]=read(),d[a[i]]=i;
		fo(i,1,m) z[i]=read(),b[z[i]]=0;
		fo(i,1,k) {
			int x=read();
			st.insert(x);
		}
		build(1,1,n);
		int fl=0;
		int p=1;
		fo(i,1,m){
			while(a[p]!=z[i]&&p<=n) p++;
			if(p>n){
				fl=1;
				pn;
				break;
			}
		}
		if(fl) continue;
		fr(i,n,1){
			if(b[i]){
				int x=get(i);
				if(st.begin()==st.end()){
					fl=1;
					pn;
					break;
				}
				auto it=(st.upper_bound(x));
				if((*st.begin())>x){
					fl=1;
					pn;
					break;
				}
				st.erase(*(it--));
				update(1,1,n,d[i]);
			}
		}
		if(fl) continue;
		py;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3252kb

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: 2ms
memory: 3316kb

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

result:

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