QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398861 | #5466. Permutation Compression | iwew# | WA | 1ms | 5696kb | C++20 | 2.9kb | 2024-04-25 19:18:24 | 2024-04-25 19:18:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int n, m, k;
int a[N], b[N], mp[N];
bool has[N];
struct Node {
int l, r;
int v, cnt;
}tr[N << 2];
void pushup(Node &u, Node &l, Node &r) {
u.v = max(l.v, r.v);
u.cnt = l.cnt + r.cnt;
}
void pushup(int u) {
pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
void build(int u, int l, int r) {
if(l == r) {
tr[u] = {l, r, a[l], 1};
} else {
tr[u] = {l, r};
int mid = (l + r) >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
int query_minl(int u, int x, int v) {
if(tr[u].v <= v) return tr[u].l;
if(tr[u].l == tr[u].r) return tr[u].l + 1;
int mid = (tr[u].l + tr[u].r) >> 1;
if(x <= mid) return query_minl(u << 1, x, v);
else {
int tmp = query_minl(u << 1 | 1, x, v);
if(tmp == mid + 1) return query_minl(u << 1, x, v);
else return tmp;
}
}
int query_maxr(int u, int x, int v) {
if(tr[u].v <= v) return tr[u].r;
if(tr[u].l == tr[u].r) return tr[u].r - 1;
int mid = (tr[u].l + tr[u].r) >> 1;
if(x > mid) return query_maxr(u << 1 | 1, x, v);
else {
int tmp = query_maxr(u << 1, x, v);
if(tmp == mid) return query_maxr(u << 1 | 1, x, v);
else return tmp;
}
}
int query(int u, int l, int r) {
if(l <= tr[u].l && tr[u].r <= r) {
return tr[u].cnt;
} else {
int res = 0;
int mid = (tr[u].l + tr[u].r) >> 1;
if(l <= mid) res += query(u << 1, l, r);
if(r > mid) res += query(u << 1 | 1, l, r);
return res;
}
}
void update(int u, int x, int v, int cnt) {
if(tr[u].l == tr[u].r) {
tr[u].v = v, tr[u].cnt = cnt;
} else {
int mid = (tr[u].l + tr[u].r) >> 1;
if(x <= mid) update(u << 1, x, v, cnt);
else update(u << 1 | 1, x, v, cnt);
pushup(u);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T -- ) {
cin >> n >> m >> k;
for(int i = 1; i <= n; i ++ ) cin >> a[i];
for(int i = 1; i <= n; i ++ ) has[i] = false, mp[a[i]] = i;
for(int i = 1; i <= m; i ++ ) {
cin >> b[i];
has[b[i]] = true;
}
vector<int> arr;
for(int i = 1; i <= n; i ++ ) {
if(!has[i]) {
arr.push_back(i);
}
}
build(1, 1, n);
multiset<int> tools;
for(int i = 0; i < k; i ++ ) {
int x;
cin >> x;
tools.insert(x);
}
bool ok = true;
for(int i = (int)arr.size() - 1; i >= 0; i -- ) {
int l = query_minl(1, mp[arr[i]], arr[i]), r = query_maxr(1, mp[arr[i]], arr[i]);
int cnt = query(1, l, r);
if(tools.empty()) {
ok = false;
break;
}
auto cur = tools.upper_bound(cnt);
// cout << "ooo " << arr[i] << ' ' << l << ' ' << r << '\n';
if(cur == tools.begin()) {
// cout << "! " << arr[i] << '\n';
ok = false;
break;
}
cur -- ;
tools.erase(cur);
update(1, mp[arr[i]], 0, 0);
}
if(ok) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5632kb
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: 5696kb
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'