QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#78380 | #5466. Permutation Compression | paspasuy | WA | 2ms | 3428kb | C++20 | 4.2kb | 2023-02-18 13:11:53 | 2023-02-18 13:11:54 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
// #define int ll
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using ar3 = array<int, 3>;
using ar2 = array<int, 2>;
using vi = vector<int>;
using vpii = vector<pii>;
using va3 = vector<ar3>;
using va2 = vector<ar2>;
using vi = vector<int>;
const int Inf = 1e9+7;
struct st {
vi t; // max, infty_cnt
int n;
st(int n) : n(n) {
t.assign(4 * n, 0);
}
void upd(int v, int vl, int vr) {
t[v] = max(t[vl], t[vr]);
}
int znach, ps;
void set(int pos, int val) {
ps = pos; znach = val;
set_t(1, 0, n);
}
void set_t(int v, int l, int r) {
if (r - l == 1) {
t[v] = znach;
return;
}
int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
if (ps < m) {
set_t(vl, l, m);
} else {
set_t(vr, m, r);
}
upd(v, vl, vr);
}
int s, e;
void collect_segs(int l, int r) {
s = l;
e = r;
collect_segs_t(1, 0, n);
}
va3 f;
void collect_segs_t(int v, int l, int r) {
if (s <= l && r <= e) {
f.push_back({v, l, r});
return;
}
if (r <= s || l >= e) {
return;
}
int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
collect_segs_t(vl, l, m);
collect_segs_t(vr, m, r);
}
int descent_right(int v, int x, int l, int r) {
if (r - l == 1) {
return l;
}
int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
if (t[vl] < x) {
return descent_right(vr, x, m, r);
} else {
return descent_right(vl, x, l, m);
}
}
int descent_left(int v, int x, int l, int r) {
if (r - l == 1) {
return l;
}
int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
if (t[vr] < x) {
return descent_left(vl, x, l, m);
} else {
return descent_left(vr, x, m, r);
}
}
int get_right(int pos, int x) {
f.clear();
collect_segs(pos + 1, n);
for (ar3 q2 : f) {
if (t[q2[0]] > x) {
int idx = descent_right(q2[0], x, q2[1], q2[2]);
return idx;
}
}
return n;
}
int get_left(int pos, int x) {
f.clear();
collect_segs(0, pos);
reverse(all(f));
for (ar3 q2 : f) {
if (t[q2[0]] > x) {
int idx = descent_left(q2[0], x, q2[1], q2[2]);
return idx;
}
}
return -1;
}
};
#define sz(arr) int((arr).size())
struct st2 {
vi t;
int n;
st2(int _n) : n(_n) {
t.assign(n, 0);
}
void set(int i, int v) {
t[i] = v;
}
int get_left(int pos, int val) {
for (int i = pos - 1; i > -1; --i) {
if (t[i] > t[pos]) {
return i;
}
}
return -1;
}
int get_right(int pos, int val) {
for (int i = pos + 1; i < n; ++i) {
if (t[i] > t[pos]) {
return i;
}
}
return n;
}
};
struct fw {
vector<ll> nums;
fw(int n) {nums.assign(n, 0);};
ll get_pf(int x) {ll ans = 0; while (x>=0) {ans += nums[x]; x = (x&(x + 1))-1;} return ans;}
ll get(int x, int y) { return get_pf(y) - get_pf(x - 1);}
void set(int x, int val) {val -= get(x, x); while (x < sz(nums)) { nums[x] += val; x |= (x + 1); }}
};
int n, m, k;
void no() {
cout << "NO\n";
}
void yes() {
cout << "YES\n";
}
void solve() {
multiset<int> tools;
cin >> n >> m >> k;
vi a(n), b(m);
vi idxa(n);
vector<char> good(n, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i]; --a[i];
idxa[a[i]] = i;
}
for (int i = 0; i < m; ++i) {
cin >> b[i]; --b[i];
good[b[i]] = 1;
}
for (int i = 0; i < m - 1; ++i) {
if (idxa[b[i]] > idxa[b[i + 1]]) {
no();
return;
}
}
for (int i = 0; i < k; ++i) {
int x; cin >> x;
tools.insert(-x);
}
st2 t(n);
fw sus(n);
for (int i = 0; i < n; ++i) {
t.set(i, a[i]);
}
int to_del = n - 1;
for (int i = 0; i < n - m; ++i) {
while (good[to_del]) {
--to_del;
}
int cur = idxa[to_del];
int lb = t.get_left(cur, to_del) + 1;
int rb = t.get_right(cur, to_del);
int len = rb - lb - sus.get(lb + 1, rb - 1);
auto best = tools.lower_bound(-len);
if (best == tools.end()) {
no();
return;
}
tools.erase(best);
t.set(cur, -Inf);
sus.set(cur, 1);
--to_del;
}
yes();
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int tt = 1;
cin >> tt;
while (tt--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3416kb
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: 2ms
memory: 3428kb
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 NO YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YE...
result:
wrong answer 46th lines differ - expected: 'YES', found: 'NO'