QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138606 | #5466. Permutation Compression | ammardab3an# | WA | 2ms | 5604kb | C++17 | 2.8kb | 2023-08-12 01:31:03 | 2023-08-12 01:31:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5 + 10;
ll st[4 * N], st1[4 * N];
vector<int> a, b, c;
void build(int v, int l, int r) {
if (l == r) {
st[v] = a[l];
st1[v] = 1;
}
else {
int mid = (l + r) / 2;
build(2 * v, l, mid);
build(2 * v + 1, mid + 1, r);
st[v] = max(st[2 * v], st[2 * v + 1]);
st1[v] = st1[2 * v] + st1[2 * v + 1];
}
}
int query(int v, int l, int r, int tl, int tr) {
if (tl > r || tr < l) return 0;
if (tl <= l && tr >= r) return st[v];
int mid = (l + r) / 2;
int f = query(2 * v, l, mid, tl, tr);
int s = query(2 * v + 1, mid + 1, r, tl, tr);
return max(f, s);
}
int query1(int v, int l, int r, int tl, int tr) {
if (tl > r || tr < l) return 0;
if (tl <= l && tr >= r) return st1[v];
int mid = (l + r) / 2;
int f = query1(2 * v, l, mid, tl, tr);
int s = query1(2 * v + 1, mid + 1, r, tl, tr);
return f + s;
}
void del(int v, int l, int r, int idx) {
if (l == r) {
st[v] = 0;
st1[v] = 0;
return;
}
int mid = (l + r) / 2;
if (idx <= mid) del(2 * v, l, mid, idx);
else del(2 * v + 1, mid + 1, r, idx);
st[v] = max(st[2 * v], st[2 * v + 1]);
st1[v] = st1[2 * v] + st1[2 * v + 1];
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
a.clear();
a.resize(n);
b.clear();
b.resize(m);
c.clear();
c.resize(k);
for (int& x : a) cin >> x;
for (int& x : b) cin >> x;
for (int& x : c) cin >> x;
sort(c.begin(), c.end());
set<int> temp(b.begin(), b.end());
vector<int> d;
int j = 0;
for (int i = 0; i < n; i++) {
if (!temp.count(a[i])) d.push_back(a[i]);
else {
if (a[i] != b[j++]) {
return cout << "NO\n", 0;
}
}
}
sort(d.begin(), d.end(), greater<int>());
build(1, 0, n - 1);
vector<int> idx(n + 1, 0);
vector<ll>need;
for (int i = 0; i < n; i++) idx[a[i]] = i;
for (int x : d) {
int nxt = idx[x], prev = idx[x];
int l = idx[x], r = n - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (query(1, 0, n - 1, idx[x], mid) <= x) {
nxt = mid;
l = mid + 1;
}
else r = mid - 1;
}
l = 0, r = idx[x];
while (l <= r) {
int mid = (l + r) / 2;
if (query(1, 0, n - 1, mid, idx[x]) <= x) {
prev = mid;
r = mid - 1;
}
else l = mid + 1;
}
int len = query1(1, 0, n - 1, prev, nxt);
need.emplace_back(len);
del(1, 0, n - 1, idx[x]);
}
bool ok = 1;
sort(need.begin(), need.end());
for (int i = 0, j = 0; i < need.size(); i++) {
if (j == c.size() || c[j] > need[i]) {
ok = 0;
break;
}
j++;
}
if (ok) cout << "YES\n";
else cout << "NO\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5604kb
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: 5600kb
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 NO
result:
wrong answer 46th lines differ - expected: 'YES', found: ''