QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75847 | #5466. Permutation Compression | XKError | WA | 3ms | 5564kb | C++14 | 1.3kb | 2023-02-06 13:05:38 | 2023-02-06 13:05:42 |
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];
multiset<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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5516kb
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: 3ms
memory: 5564kb
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'