QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#796461 | #5466. Permutation Compression | yyksam | WA | 1ms | 3656kb | C++14 | 3.9kb | 2024-12-01 19:20:33 | 2024-12-01 19:20:33 |
Judging History
answer
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;
int lowbit(int x) {
return (x & (-x));
}
struct tree_array {
int n;
vector<ll> t1, t2;
tree_array(int n) {
this->n = n;
t1.resize(n + 10);
t2.resize(n + 10);
}
void insert(int l, int r, ll x) {
update(l, x);
update(r + 1, -x);
}
void update(int idx, ll x) {
for (int i = idx; i <= n; i += lowbit(i)) {
t1[i] += x;
t2[i] += (ll)idx * x;
}
}
ll getsum(int idx) {
ll res = 0;
for (int i = idx; i; i -= lowbit(i)) {
res += ((ll)idx + 1) * t1[i] - t2[i];
}
return res;
}
};
int stk[N], top, ix[N];
tree<pair<int, int>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> treap;
void work() {
int n, m, k, cnt = 0;
cin >> n >> m >> k;
tree_array left(n), right(n);
treap.clear();
vector<int> a(n + 1), b(m + 1), c(k + 1);
vector<bool> isc(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
for (int i = 1; i <= k; i++) {
cin >> c[i];
treap.insert({c[i], ++cnt});
}
if (k < n - m) {
cout << "NO\n";
return;
}
int idx = 1;
vector<pii> gai;
for (int i = 1; i <= m; i++) {
while (a[idx] != b[i] && idx <= n) {
isc[idx] = true;
gai.emplace_back(a[idx], idx);
idx++;
}
if (idx > n) {
cout << "NO\n";
return;
}
idx++;
}
while (idx <= n) isc[idx++] = true;
sort(gai.begin(), gai.end(), [&](pii a, pii b) {
return a.first > b.first;
});
auto bin_search = [&](int k, int def) {
int l = 1, r = top, res = def;
while (l <= r) {
int mid = l + r >> 1;
if (stk[mid] > k) {
res = ix[mid];
r = mid - 1;
}
else l = mid + 1;
}
return res;
};
top = 0;
for (int i = 1; i <= n; i++) {
if (isc[i]) {
//cout << i << " " << i - bin_search(a[i], 0) << '\n';
left.insert(i, i, i - bin_search(a[i], 0));
}
else {
while (top && stk[top] <= a[i]) top--;
stk[++top] = a[i];
ix[top] = i;
}
}
top = 0;
for (int i = n; i >= 1; i--) {
if (isc[i]) {
//cout << i << " " << bin_search(a[i], n + 1) - i << '\n';
right.insert(i, i, bin_search(a[i], n + 1) - i);
}
else {
while (top && stk[top] <= a[i]) top--;
stk[++top] = a[i];
ix[top] = i;
}
}
for (int i = 0; i < gai.size(); i++) {
int num = gai[i].first, dis = gai[i].second;
int l = 1, r = k - i, ans = -1;
int l_dis = left.getsum(dis) - left.getsum(dis - 1);
int r_dis = right.getsum(dis) - right.getsum(dis - 1);
while (l <= r) {
int mid = l + r >> 1;
int len = (*treap.find_by_order(mid - 1)).first;
if (len <= l_dis + r_dis - 1) {
ans = len;
l = mid + 1;
}
else r = mid - 1;
}
if (ans == -1) {
cout << "NO\n";
return;
}
//cout << ans << '\n';
treap.erase(treap.upper_bound({ans, 0}));
left.insert(dis + 1, dis + r_dis - 1, -1);
right.insert(dis - l_dis + 1, dis - 1, -1);
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
work();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 3656kb
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 NO 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 Y...
result:
wrong answer 28th lines differ - expected: 'NO', found: 'YES'