QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709555 | #4780. 完美的队列 | NineSuns | 0 | 30ms | 86872kb | C++14 | 3.7kb | 2024-11-04 15:26:27 | 2024-11-04 15:26:36 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5+5, B = N, b = 317, inf = 0x3f3f3f3f;
int n, m, a[N], l[N], r[N], x[N], rk[N], lb[B], rb[B], sr[N], cb[B], sa[N], bv[N], ans[N], ed;
pii stk[N];
vector <int> dx[B], col[N];
deque <pii> qs[N];
set <pii> qb[B];
int mx, ad;
void chk (int id, int x, int k) {
if (l[id] <= lb[x] && rb[x] <= r[id]) {
mx += k; ad += k;
return;
}
if (l[id] > rb[x] || r[id] < lb[x]) return;
mx = -inf;
for (int j = max(l[id], lb[x]);j <= min(r[id], rb[x]);j++) bv[j] -= k, mx = max(mx, bv[j]+ad);
}
void solve () {
cin >> n >> m;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= m;i++) cin >> l[i] >> r[i] >> x[i], col[x[i]].pb(i);
for (int i = 1; ;i++) {
lb[i] = rb[i-1]+1; rb[i] = min(n, rb[i-1]+b);
for (int j = lb[i];j <= rb[i];j++) rk[j] = i;
if (rb[i] == n) break;
}
for (int i = 1;i <= m;i++) {
if (rk[l[i]] == rk[r[i]]) {
for (int j = l[i];j <= r[i];j++) {
sa[j]++;
while (qs[j].size() && sa[j]+cb[rk[j]] >= qs[j].front().fi) {
qb[rk[j]].erase({qs[j].front().fi-sa[j]+1, j});
sr[qs[j].front().se] = max(sr[qs[j].front().se], i-1), qs[j].pop_front();
}
qs[j].pb({cb[rk[j]]+sa[j]+a[j], i});
qb[rk[j]].insert({qs[j].front().fi-sa[j], j});
}
}
else {
// for (int j = l[i];j <= rb[rk[l[i]]];j++) {
// sa[j]++;
// while (qs[j].size() && sa[j]+cb[rk[j]] >= qs[j].front().fi) {
// qb[rk[j]].erase({qs[j].front().fi-sa[j]+1, j});
// sr[qs[j].front().se] = max(sr[qs[j].front().se], i-1), qs[j].pop_front();
// }
// qs[j].pb({cb[rk[j]]+sa[j]+a[j], i});
// qb[rk[j]].insert({qs[j].front().fi-sa[j], j});
// }
// for (int j = lb[rk[r[i]]];j <= r[i];j++) {
// sa[j]++;
// while (qs[j].size() && sa[j]+cb[rk[j]] >= qs[j].front().fi) {
// qb[rk[j]].erase({qs[j].front().fi-sa[j]+1, j});
// sr[qs[j].front().se] = max(sr[qs[j].front().se], i-1), qs[j].pop_front();
// }
// qs[j].pb({cb[rk[j]]+sa[j]+a[j], i});
// qb[rk[j]].insert({qs[j].front().fi-sa[j], j});
// }
// for (int j = rk[l[i]]+1;j < rk[r[i]];j++) {
// cb[j]++;
// while (qb[j].size()) {
// auto k = *qb[j].begin();
// if (k.fi > cb[j]) break;
// qb[j].erase(k);
// sr[qs[k.se].front().se] = max(sr[qs[k.se].front().se], i-1);
// qs[k.se].pop_front();
// if (qs[k.se].size()) qb[j].insert({qs[k.se].front().fi-sa[k.se], k.se});
// }
// dx[j].pb(i);
// }
}
}
for (int i = 1;i <= rk[n];i++) {
int l = 1, r = 0; mx = -inf; ad = 0;
for (int z = lb[i];z <= rb[i];z++) mx = max(mx, a[z]), bv[z] = a[z];
for (int j : dx[i]) {
while (r < j) ++r, chk(r, i, -1);
while (l <= j) chk(l, i, 1), l++;
while (r < n && mx > 0) ++r, chk(r, i, -1);
if (mx > 0) sr[j] = max(sr[j], n);
else sr[j] = max(sr[j], r-1);
}
}
for (int i = 1;i <= n;i++) while (qs[i].size()) sr[qs[i].front().se] = n, qs[i].pop_front();
for (int i = 1;i <= 1e5;i++) {
reverse(col[i].begin(), col[i].end());
for (int j : col[i]) {
int r = sr[j];
while (ed && stk[ed].fi <= r) {
r = max(r, stk[ed].se); ed--;
}
stk[++ed] = {j, r};
}
while (ed) {
ans[stk[ed].fi]++; ans[stk[ed].se+1]--;
ed--;
}
}
for (int i = 1;i <= m;i++) ans[i] += ans[i-1];
for (int i = 1;i <= m;i++) cout << ans[i] << '\n';
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 22ms
memory: 84328kb
input:
5000 4999 99 36 47 78 58 58 64 12 42 54 29 56 57 32 99 21 1 6 42 97 82 8 79 92 3 56 19 41 29 59 23 34 76 34 82 20 44 51 60 73 89 65 51 65 15 87 65 70 51 26 40 95 44 62 97 81 43 13 20 81 76 64 47 95 54 56 99 62 91 63 98 58 70 60 47 97 31 74 76 70 10 30 99 33 52 100 14 65 4 6 87 4 8 1 8 87 18 70 76 43...
output:
-4564 -4563 -4562 -4561 -4560 -4559 -4558 -4557 -4556 -4555 -4554 -4553 -4552 -4551 -4550 -4549 -4548 -4547 -4546 -4545 -4544 -4543 -4542 -4541 -4540 -4539 -4538 -4537 -4536 -4535 -4534 -4533 -4532 -4531 -4530 -4529 -4528 -4527 -4526 -4525 -4524 -4523 -4522 -4521 -4520 -4519 -4518 -4517 -4516 -4515 ...
result:
wrong answer 1st numbers differ - expected: '1', found: '-4564'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 20ms
memory: 85816kb
input:
25000 25000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
-24529 -24528 -24527 -24526 -24525 -24524 -24523 -24522 -24521 -24520 -24519 -24518 -24517 -24516 -24515 -24514 -24513 -24512 -24511 -24510 -24509 -24508 -24507 -24506 -24505 -24504 -24503 -24502 -24501 -24500 -24499 -24498 -24497 -24496 -24495 -24494 -24493 -24492 -24491 -24490 -24489 -24488 -24487...
result:
wrong answer 1st numbers differ - expected: '1', found: '-24529'
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 19ms
memory: 86672kb
input:
34999 35000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
-34542 -34541 -34540 -34539 -34538 -34537 -34536 -34535 -34534 -34533 -34532 -34531 -34530 -34529 -34528 -34527 -34526 -34525 -34524 -34523 -34522 -34521 -34520 -34519 -34518 -34517 -34516 -34515 -34514 -34513 -34512 -34511 -34510 -34509 -34508 -34507 -34506 -34505 -34504 -34503 -34502 -34501 -34500...
result:
wrong answer 1st numbers differ - expected: '1', found: '-34542'
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 29ms
memory: 86456kb
input:
45000 45000 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
output:
-44527 -44526 -44525 -44524 -44523 -44522 -44521 -44520 -44519 -44518 -44517 -44516 -44515 -44514 -44513 -44512 -44511 -44510 -44509 -44508 -44507 -44506 -44505 -44504 -44503 -44502 -44501 -44500 -44499 -44498 -44497 -44496 -44495 -44494 -44493 -44492 -44491 -44490 -44489 -44488 -44487 -44486 -44485...
result:
wrong answer 1st numbers differ - expected: '1', found: '-44527'
Subtask #10:
score: 0
Skipped
Dependency #8:
0%
Subtask #11:
score: 0
Skipped
Dependency #5:
0%
Subtask #12:
score: 0
Skipped
Dependency #11:
0%
Subtask #13:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 30ms
memory: 86872kb
input:
65000 65000 5 7 8 6 3 6 8 7 2 3 5 10 9 9 4 3 9 1 2 9 1 1 6 10 1 10 5 4 7 1 9 6 6 8 10 5 8 3 2 5 2 3 6 8 7 3 2 3 6 5 1 10 6 2 4 7 8 1 3 3 5 4 2 5 2 5 3 3 6 7 6 9 5 3 10 3 6 2 8 10 9 10 2 5 4 10 3 3 6 3 5 7 141 3 6 3 10 2 7 6 3 5 9 4 10 1 3 9 9 8 2 5 10 1 7 1 8 5 3 3 7 7 9 7 4 1 9 2 2 4 8 6 10 5 7 3 3...
output:
-64583 -64582 -64581 -64580 -64579 -64578 -64577 -64576 -64575 -64574 -64573 -64572 -64571 -64570 -64569 -64568 -64567 -64566 -64565 -64564 -64563 -64562 -64561 -64560 -64559 -64558 -64557 -64556 -64555 -64554 -64553 -64552 -64551 -64550 -64549 -64548 -64547 -64546 -64545 -64544 -64543 -64542 -64541...
result:
wrong answer 1st numbers differ - expected: '1', found: '-64583'
Subtask #14:
score: 0
Skipped
Dependency #12:
0%
Subtask #15:
score: 0
Skipped
Dependency #13:
0%
Subtask #16:
score: 0
Skipped
Dependency #14:
0%
Subtask #17:
score: 0
Skipped
Dependency #16:
0%
Subtask #18:
score: 0
Skipped
Dependency #17:
0%
Subtask #19:
score: 0
Skipped
Dependency #18:
0%
Subtask #20:
score: 0
Skipped
Dependency #19:
0%