QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#75845 | #5466. Permutation Compression | XKError | WA | 2ms | 5736kb | C++14 | 1.3kb | 2023-02-06 13:02:21 | 2023-02-06 13:02:23 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
int n, m, k;
int a[maxn];
int b[maxn];
int p[maxn];
int q[maxn];
set<int> s, t;
int ft[maxn];
void add(int x, int k) {
for (; x <= n; x += x & -x) ft[x] += k;
}
int qry(int l, int r) {
int res = 0;
for (int x = l - 1; x; x -= x & -x) res -= ft[x];
for (int x = r; x; x -= x & -x) res += ft[x];
return res;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) ft[i] = p[i] = q[i] = 0;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) p[a[i]] = i;
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
for (int i = 1; i <= m; i++) q[b[i]] = i;
for (int i = 1; i <= n; i++) add(i, 1);
s.clear();
t.clear();
t.insert(0);
t.insert(n + 1);
while (k--) {
int x;
scanf("%d", &x);
s.insert(x);
}
for (int i = n; i; i--) {
if (q[i]) t.insert(p[i]);
else {
int r = *t.lower_bound(p[i]);
int l = *--t.lower_bound(p[i]);
int len = qry(l + 1, r - 1);
auto tmp = s.upper_bound(len);
// cout<<*tmp<<"!"<<endl;
if (tmp == s.begin()) {
puts("NO");
goto B;
}
s.erase(--tmp);
add(p[i], -1);
}
}
puts("YES");
B:;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5484kb
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: 5736kb
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 NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES NO YES YES YES YES YES NO NO YES YES YES NO NO NO NO YES NO YES YES YES YES YES YES NO YES NO YES NO YES NO NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES...
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'