QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258994 | #5466. Permutation Compression | kai_wei | WA | 1ms | 3360kb | C++20 | 2.9kb | 2023-11-20 15:34:02 | 2023-11-20 15:34:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1), query(n + 1), tool(k + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
query[x] = 1;
}
for (int i = 1; i <= k; i++) {
cin >> tool[i];
}
sort(tool.begin() + 1, tool.end(), greater<int>());
vector<int> st;
vector<pair<int, int>> inter(n + 1);
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[st.back()] < a[i]) {
// cout << a[st.back()] << ' ' << a[i] << ' ' << i << endl;
inter[a[st.back()]].second = i - 1;
// 计算每个数区间的右端点
st.pop_back();
}
st.push_back(i);
}
while (!st.empty()) {
inter[a[st.back()]].second = n;
st.pop_back();
}
for (int i = n; i >= 1; i--) {
while (!st.empty() && a[st.back()] < a[i]) {
inter[a[st.back()]].first = i + 1;
// 计算每个数区间的左端点
st.pop_back();
}
st.push_back(i);
}
while (!st.empty()) {
inter[a[st.back()]].first = 1;
st.pop_back();
}
// int cnt = 0;
// for (int i = 1; i <= n; i++) {
// cout << ++cnt << ' ';
// cout << inter[i].first << ' ' << inter[i].second << endl;
// }
int pos = 1;
int ans = 0;
for (int i = n; i >= 1; i--) {
if (query[i] == 0) {
int len = inter[i].second - inter[i].first + 1;
// cout << len << ' ' << i << endl;
while (pos <= k && len < tool[pos]) {
pos++;
}
if (pos > k) {
ans = -1;
break;
}
pos++;
if (i != 1 && query[i - 1] == 0) {
if (inter[i].first < inter[i - 1].first && inter[i].second >= inter[i - 1].second) {
inter[i - 1].first = inter[i].first;
inter[i - 1].second = inter[i].second - 1;
} else if (inter[i].first <= inter[i - 1].first && inter[i].second > inter[i - 1].second) {
inter[i - 1].first = inter[i].first + 1;
inter[i - 1].second = inter[i].second;
}
}
}
}
// cout << pos << endl;
if (ans == -1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3352kb
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: 1ms
memory: 3360kb
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'