QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671741 | #5466. Permutation Compression | ucup-team5217# | WA | 3ms | 13892kb | C++23 | 2.8kb | 2024-10-24 14:17:19 | 2024-10-24 14:17:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N], b[N], l[N];
int pos[N], del[N], vis[N];
int n, m, k;
int pre[N], nxt[N];
int q[N], top;
struct Bit {
int val[N];
void add(int x, int v) {
for (int i = x; i <= n; i += (i & -i)) {
// vla[i] += v;
val[i] += v;
}
}
void clear() {
for (int i = 1; i <= n; ++i) val[i] = 0;
}
int query(int x, int y) {
int res = 0;
for (int i = y; i; i -= (i & -i)) {
res += val[i];
}
for (int i = x - 1; i; i -= (i & -i)) {
res -= val[i];
}
return res;
}
}bit;
void solve() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
for (int i = 1; i <= n; ++i) del[i] = 1;
for (int i = 1; i <= n; ++i) vis[i] = 0;
for (int i = 0; i <= n + 1; ++i) pre[i] = nxt[i] = 0;
bit.clear();
for (int i = 1; i <= m; ++i) {
scanf("%d", &b[i]);
del[b[i]] = 0;
vis[pos[b[i]]] = 1;
}
multiset<int> s;
for (int i = 1; i <= k; ++i) {
scanf("%d", &l[i]);
s.insert(l[i]);
}
top = 0;
q[0] = 0;
for (int i = 1; i <= n; ++i) {
if (vis[i]) {
while (top && a[i] > a[q[top]]) {
--top;
}
q[++top] = i;
}
else {
int l = 0, r = top;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (a[q[mid]] > a[i]) l = mid;
else r = mid - 1;
}
pre[i] = q[l];
}
}
top = 0;
q[0] = n + 1;
for (int i = n; i; --i) {
if (vis[i]) {
while (top && a[i] > a[q[top]]) {
--top;
}
q[++top] = i;
}
else {
int l = 0, r = top;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (a[q[mid]] > a[i]) l = mid;
else r = mid - 1;
}
nxt[i] = q[l];
}
}
if (k + m < n) {
puts("NO");
return ;
}
for (int i = n; i >= 1; --i) {
if (del[i]) {
int x = pos[i];
int val = nxt[x] - pre[x] - 1 - bit.query(pre[x] + 1, nxt[x] - 1);
auto it = s.upper_bound(val);
if (it == s.begin()) {
puts("NO");
return ;
}
s.erase(--it);
bit.add(x, 1);
}
}
puts("YES");
return ;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13892kb
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: 0ms
memory: 13884kb
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'