QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#520658 | #5466. Permutation Compression | no_RED_no_DEAD | WA | 3ms | 16168kb | C++20 | 3.9kb | 2024-08-15 14:45:07 | 2024-08-15 14:45:08 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll N = 1e6 + 1;
const ll M = 1e9 + 7;
struct SparseTable {
vector<ll> a; vector<vector<ll>> mi, ma;
SparseTable(ll *arr, ll n): a(n + 1), mi(n + 1, vector<ll>(__lg(n + 1) + 1)), ma(n + 1, vector<ll>(__lg(n + 1) + 1)) {
for (int i = 1; i <= n; i ++) a[i] = arr[i], mi[i][0] = ma[i][0] = i;
for (int j = 1; j <= __lg(n); j ++)
for (ll i = 1; i + (1 << j) - 1 <= n; i ++)
mi[i][j] = (a[mi[i][j - 1]] <= a[mi[i + (1 << (j - 1))][j - 1]]) ? (mi[i][j - 1]) : (mi[i + (1 << (j - 1))][j - 1]),
ma[i][j] = (a[ma[i][j - 1]] >= a[ma[i + (1 << (j - 1))][j - 1]]) ? (ma[i][j - 1]) : (ma[i + (1 << (j - 1))][j - 1]);
}
ll getMaxIndex(ll l, ll r) {ll k = __lg(r - l + 1); return (a[ma[l][k]] >= a[ma[r - (1 << k) + 1][k]]) ? ma[l][k] : ma[r - (1 << k) + 1][k];}
ll getMax(ll l, ll r) {return a[getMaxIndex(l, r)];}
ll getMinIndex(ll l, ll r) {ll k = __lg(r - l + 1); return (a[mi[l][k]] <= a[mi[r - (1 << k) + 1][k]]) ? mi[l][k] : mi[r - (1 << k) + 1][k];}
ll getMin(ll l, ll r) {return a[getMinIndex(l, r)];}
};
ll n, m, k;
ll a[N], b[N], l[N], lb[N], rb[N], pp[N];
vector<ll> seq[N];
bool inorder() {
ll j = 1;
for (int i = 1; i <= n; i ++)
if (a[i] == b[j]) j ++;
return (j >= m + 1);
}
void doTest(ll testID) {
ll sz = 0;
auto add = [&](vector<ll> &cur) -> void {
if (cur.size() == 0) return;
seq[++ sz] = cur; lb[sz] = cur[0]; rb[sz] = cur.back();
};
cin >> n >> m >> k;
for (int i = 1; i <= n; i ++) cin >> a[i]; SparseTable st(a, n);
for (int i = 1; i <= m; i ++) cin >> b[i];
for (int i = 1; i <= k; i ++) cin >> l[i];
if (k + m < n) {cout << "NO\n"; return;}
if (!inorder()) {cout << "NO\n"; return;}
for (int i = 1; i <= n; i ++) pp[a[i]] = 1;
for (int i = 1; i <= m; i ++) pp[b[i]] = 0;
vector<ll> cur;
for (int i = 1; i <= n; i ++) {
if (pp[a[i]] == 0) add(cur), cur.clear();
else cur.push_back(i);
} add(cur);
// cout << "<SEQ>" << endl;
// for (int i = 1; i <= sz; i ++) cout << seq[i].size() << ' ' << lb[i] << ' ' << rb[i] << endl;
for (int i = 1; i <= sz; i ++) {
for (auto &x: seq[i]) x = a[x];
sort(seq[i].begin(), seq[i].end(), greater<ll>());
}
vector<ll> res;
for (int i = 1; i <= sz; i ++) {
ll cur = seq[i].size();
for (auto x: seq[i]) {
ll lcnt = 0, rcnt = 0, lpos = lb[i] - 1, rpos = rb[i] + 1;
if (lpos >= 1) {
ll l = 1, r = lpos, mid, res = -1;
while (r >= l) {
mid = (r + l) >> 1;
if (st.getMax(mid, lpos) <= x) r = (res = mid) - 1;
else l = mid + 1;
}
if (res != -1) lcnt = lpos - res + 1;
}
if (rpos <= n) {
ll l = rpos, r = n, mid, res = -1;
while (r >= l) {
mid = (r + l) >> 1;
if (st.getMax(rpos, mid) <= x) l = (res = mid) + 1;
else r = mid - 1;
}
if (res != -1) rcnt = res - rpos + 1;
}
// cout << "Debug: " << x << ' ' << cur << ' ' << lcnt << ' ' << rcnt << endl;
res.push_back(cur + lcnt + rcnt); cur --;
}
}
// cout << "<RES>: "; for (auto x : res) cout << x << ' '; cout << endl;
sort(res.begin(), res.end());
sort(l + 1, l + k + 1);
for (int i = 0; i < res.size(); i ++)
if (res[i] < l[i + 1]) {cout << "NO\n"; return;}
cout << "YES\n";
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int test = 1;
cin >> test;
for (int _ = 1; _ <= test; _ ++) doTest(test);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 15928kb
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: 0
Accepted
time: 0ms
memory: 16168kb
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 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 YE...
result:
ok 100 lines
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 15868kb
input:
99 6 1 6 1 5 3 4 2 6 1 1 2 1 1 1 6 1 1 1 1 1 1 4 1 3 3 4 1 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 3 2 2 3 2 1 2 1 1 2 3 3 1 2 3 1 2 3 1 1 6 1 5 3 4 2 5 6 1 3 4 2 1 1 1 6 4 4 1 6 5 2 3 4 1 2 3 4 5 4 4 6 2 1 1 1 2 1 1 6 5 1 2 1 4 5 6 3 2 1 4 6 3 2 6 3 6 5 6 2 1 3...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES NO 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 YES YES YES NO NO YES YES YES NO YES YES YES NO YES YES NO YES NO YES NO YES YES YES YES YES YES NO YES NO NO YES YES YES YES...
result:
wrong answer 20th lines differ - expected: 'YES', found: 'NO'