QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547472 | #5466. Permutation Compression | Sunlight9 | WA | 1ms | 5720kb | C++20 | 4.9kb | 2024-09-04 21:59:54 | 2024-09-04 22:00:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int Maxn = 2e5 + 3;
struct Segmentree {
int maxx[Maxn * 4], lzt[Maxn * 4];
int lc(int p) {return p << 1;}
int rc(int p) {return p << 1 | 1;}
void pushup(int p) {
maxx[p] = max(maxx[lc(p)], maxx[rc(p)]);
}
// void pushdown(int l, int r, int mid, int p) {
// if (!lzt[p]) return;
// maxx[lc(p)] += lzt[p];
// maxx[rc(p)] += lzt[p];
// lzt[lc(p)] += lzt[p];
// lzt[rc(p)] += lzt[p];
// lzt[p] = 0;
// }
void build(int l, int r, int p, vector<int> &a) {
if (l == r) {
maxx[p] = a[l];
lzt[p] = 0;
return;
}
int mid = l + ((r - l) >> 1);
build(l, mid, lc(p), a);
build(mid + 1, r, rc(p), a);
pushup(p);
}
//[l,r]是结点p覆盖的区间, [s,t]是要修改的区间
void modify(int l, int r, int d, int s, int t, int p) {
if (s <= l && r <= t) {
maxx[p] += d;
// lzt[p] += d;
return;
}
int mid = l + ((r - l) >> 1);
// pushdown(l, r, mid, p);
if (s <= mid) modify(l, mid, d, s, t, lc(p));
if (t > mid) modify(mid + 1, r, d, s, t, rc(p));
pushup(p);
}
int query(int l, int r, int s, int t, int p) {
if (s <= l && r <= t) return maxx[p];
int mid = l + ((r - l) >> 1);
int res = 0;
// pushdown(l, r, mid, p);
if (s <= mid) res = max(res, query(l, mid, s, t, lc(p)));
if (t > mid) res = max(res, query(mid + 1, r, s, t, rc(p)));
return res;
}
//从右往左找第一个大于val的位置, 从t到s
int query1(int l, int r, int s, int t, int p, int val) {
if (l == r) return l;
int mid = l + ((r - l) >> 1);
// pushdown(l, r, mid, p);
int res = 0;
if (t > mid) {
if (maxx[rc(p)] > val) {
res = query1(mid + 1, r, s, t, rc(p), val);
}
}
if (res) return res;
if (s <= mid) {
if (maxx[lc(p)] > val) {
res = query1(l, mid, s, t, lc(p), val);
}
}
return res;
}
int query2(int l, int r, int s, int t, int p, int val) {
if (l == r) return l;
int mid = l + ((r - l) >> 1);
// pushdown(l, r, mid, p);
int res = 0;
if (s <= mid) {
if (maxx[lc(p)] > val) {
res = query2(l, mid, s, t, lc(p), val);
}
}
if (res) return res;
if (t > mid) {
if (maxx[rc(p)] > val) {
res = query2(mid + 1, r, s, t, rc(p), val);
}
}
return res;
}
}seg;
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<int> b(m + 1);
for (int i = 1; i <= m; ++i) {
cin >> b[i];
}
vector<int> len(k + 1);
multiset<int> s;
for (int i = 1; i <= k; ++i) {
cin >> len[i];
s.insert(-len[i]);
}
int it = 1;
vector<array<int, 2> > tod;
for (int i = 1; i <= n; ++i) {
if (it <= m && a[i] == b[it]) {
it++;
} else {
tod.push_back({a[i], i});
}
}
if (it <= m) {
cout << "NO\n";
return;
}
sort(tod.begin(), tod.end(), greater());
// for (int i = 0; i < ssize(tod); ++i) {
// cerr << tod[i] << " \n"[i == ssize(tod) - 1];
// }
seg.build(1, n, 1, a);
// cerr << seg.query1(1, n, 1, 4, 1, 5) << '\n';
// cerr << seg.query2(1, n, 4, n, 1, 10) << '\n';
for (int i = 0; i < ssize(tod); ++i) {
int l = seg.query1(1, n, 1, tod[i][1], 1, tod[i][0]);
if (!l) l = 1;
else l++;
int r = seg.query2(1, n, tod[i][1], n, 1, tod[i][0]);
if (!r) r = n;
else r--;
int len = r - l + 1;
// cerr << tod[i][0] << ' ' << l << ' ' << r << ' ' << len << " \n";
auto f = s.lower_bound(-len);
if (f == s.end()) {
cout << "NO\n";
return;
} else {
// s.erase(f);
s.extract(-len);
seg.modify(1, n, -tod[i][0], tod[i][1], tod[i][1], 1);
}
}
it = 1;
for (int i = 1; i <= n; ++i) {
int x = seg.query(1, n, i, i, 1);
if (x) {
if (it > m) {
cout << "NO\n";
return;
}
if (x != b[it]) {
cout << "NO\n";
return;
}
it++;
}
}
cout << "YES\n";
}
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int _;
cin >> _;
while (_--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5720kb
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: 5624kb
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 YES YES YES YES YES YES YES YES YES YES YES NO YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
wrong answer 28th lines differ - expected: 'NO', found: 'YES'