QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#216168 | #5466. Permutation Compression | ucup-team059# | WA | 0ms | 3844kb | C++20 | 1.9kb | 2023-10-15 16:23:39 | 2023-10-15 16:23:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using vi = vector<int>;
#define lowbit(x) ( x & - x )
struct BinaryIndexedTree {
int n;
vi b;
BinaryIndexedTree(int n = 1) : n(n), b(n + 1, 0) {}
void update(int i, int y) {
for (; i <= n; i += lowbit(i)) b[i] += y;
}
int calc(int i) {
int sum = 0;
for (; i; i -= lowbit(i)) sum += b[i];
return sum;
}
int calc(int l, int r) {
assert(l <= r);
if (l == 0) return calc(r);
return calc(r) - calc(l - 1);
}
};
void solve() {
set<int> st, length;
int n, m, k;
cin >> n >> m >> k;
vi a(n + 1), b(m + 1);
vi vis(n + 1), pos(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i], pos[a[i]] = i;
for (int i = 1; i <= m; i++)
cin >> b[i], vis[b[i]] = 1;
for (int i = 1, x; i <= k; i++)
cin >> x, length.insert(x);
// 判断顺序不对
for (int i = 1, j = 1; i <= m; i++) {
while (j <= n and a[j] != b[i]) j++;
if (j > n) {
cout << "NO\n";
return;
}
}
BinaryIndexedTree bit(n);
for (int i = 1; i <= n; i++)
bit.update(i, 1);
st.insert(0), st.insert(n + 1);
for (int i = n; i >= 1; i--) { // 枚举值
if (vis[i]) {
st.insert(pos[i]);
continue;
}
auto ps = st.lower_bound(pos[i]);
int l = *prev(ps), r = *ps;
int len = bit.calc(r - 1) - bit.calc(l);
bit.update(pos[i], -1);
auto it = length.upper_bound(len);
if (it == length.begin()) {
cout << "NO\n";
return;
}
length.erase(--it);
}
cout << "YES\n";
return;
}
int32_t main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int TC;
for (cin >> TC; TC; TC--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3844kb
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 NO 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'