QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592243 | #5466. Permutation Compression | Baiyu0123# | WA | 1ms | 5704kb | C++20 | 1.6kb | 2024-09-26 21:28:53 | 2024-09-26 21:28:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100,lim=1e6;
int sum[maxn<<2],n;
int b[maxn],a[maxn],p[maxn],bl[maxn];
set<int> s;
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++) {
cin>>b[i];
}
int bw=1;
sort(b+1,b+k+1,cmp);
s.insert(0);s.insert(n+1);
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);
while (bw<=k&&b[bw]>ret) bw++;
if (bw<=k) {
bw++;
modify(w,1,n,1);
} else ans=0;
}
}
if (ans) cout<<"YES\n";
else cout<<"NO\n";
s.clear();
for (int i=1;i<=n;i++) bl[i]=0;
}
}
详细
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: 5704kb
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'