QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88994 | #5466. Permutation Compression | shiyihangxs | WA | 2ms | 3544kb | C++14 | 2.6kb | 2023-03-18 09:48:44 | 2023-03-18 09:48:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mpr make_pair
//mt19937_64 ra(time(0) ^ (*new char));
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
const int SIZE = 200005;
const int mod = 998244353;
int n, m, K, T;
int a[SIZE], b[SIZE];
int l[SIZE];
bool v[SIZE], used[SIZE];
int st[SIZE], top;
int nx[SIZE], pr[SIZE];
int c[SIZE];
inline int rd(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x*f;
}
bool cmp(int x, int y){
return a[x] > a[y];
}
int lowbit(int x){
return x & (-x);
}
void add(int x, int val){
for(int i = x; i <= n; i+=lowbit(i)) c[i] += val;
}
int ask(int x){
int jl = 0;
for(int i = x; i; i-=lowbit(i)) jl += c[i];
return jl;
}
int main(){
T = rd();
while(T--){
n = rd(), m = rd(), K = rd();
for(int i = 1; i <= n; i++) c[i] = 0;
for(int i = 1; i <= n; i++) a[i] = rd(), v[i] = 1, add(i, 1);
for(int i = 1; i <= m; i++) b[i] = rd(), v[b[i]] = 0;
for(int i = 1; i <= K; i++) l[i] = rd(), used[i] = 0;
sort(l+1, l+K+1); top = 0;
for(int i = 1; i <= n; i++){
while(top && a[st[top]] < a[i]) nx[st[top]] = i, top--;
st[++top] = i;
}
while(top) nx[st[top]] = n+1, top--;
for(int i = n; i >= 1; i--){
while(top && a[st[top]] < a[i]) pr[st[top]] = i, top--;
st[++top] = i;
}
while(top) pr[st[top]] = 0, top--;
for(int i = 1; i <= n; i++){
if(v[a[i]]) st[++top] = i;
v[a[i]] = 0;
}
v[0] = v[n+1] = 0;
sort(st+1, st+top+1, cmp);
// for(int i = 1; i <= top; i++) printf("%d ", st[i]);
// puts("");
bool ans = 1;
for(int i = 1; i <= top; i++){
int prr = pr[st[i]], nxx = nx[st[i]];
while(v[prr]) prr = pr[prr];
while(v[nxx]) nxx = nx[nxx];
prr++, nxx--;
// cout << prr << " " << nxx << endl;
int x = ask(nxx) - (prr==1?0:ask(prr-1)), jjl = 0;
// cout << x << endl;
for(int j = K; j >= 1; j--){
if(l[j] > x || used[j]) continue;
jjl = j; break;
}
if(jjl == 0){
ans = 0;
break;
}
used[jjl] = 1; v[st[i]] = 1; add(st[i], -1);
}
if(ans == 0){
printf("NO\n");
continue;
}
int now = 1;
for(int i = 1; i <= n; i++){
if(!v[i]){
if(a[i] == b[now]) now++;
else{
ans = 0;
break;
}
}
}
if(now != m+1) ans = 0;
if(ans) printf("YES\n");
else printf("NO\n");
}
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3492kb
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: 2ms
memory: 3544kb
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: 1ms
memory: 3304kb
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 YES 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 YES YES YES YES YES YES YES NO YES NO YES YES YES YES ...
result:
wrong answer 65th lines differ - expected: 'NO', found: 'YES'