QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356137 | #4780. 完美的队列 | Nelofus | 0 | 414ms | 235752kb | C++20 | 4.5kb | 2024-03-17 16:00:13 | 2024-03-17 16:00:14 |
Judging History
answer
/*
* Copyright© 2024 Heratino & Nelofus. All rights reserved.
* author: Heratino & Nelofus
* Problem: QOJ#4780. 完美的队列
* Tag: 分块;树状数组
* Memory Limit: 256MB
* Time Limit: 5000ms
* Source: 集训队互测 2018
* Date: 2024-03-15
*/
// Narcissus & どうか安寧な記憶を
#include <bits/stdc++.h>
using i64 = long long;
using f64 = double;
constexpr int N = 1e5 + 10;
constexpr int N2 = 1e5;
constexpr int M = 210;
struct query {
int l, r;
int x;
int t;
} Q[N];
int n, m;
int a[N];
int bl[M], br[M], pos[N];
int B, bcnt;
void blockInit() {
B = std::ceil(sqrt((f64)n / log2(m)));
bcnt = (n - 1) / B + 1;
for (int i = 1; i <= bcnt; i++) {
bl[i] = (i - 1) * B + 1;
br[i] = i * B;
}
br[bcnt] = std::min(br[bcnt], n);
for (int i = 1; i <= n; i++)
pos[i] = (i - 1) / B + 1;
}
// 维护二元组 (x, k), 表示颜色 x 的出现次数增加了 k, k = ±1
std::vector<std::pair<int, int>> delta[N];
int seq[N];
// {{{处理整块
void solveBlock(const int &x) {
int r = 0;
/* 维护序列里最后一个被删掉的 */
int tag = 0, mxval = -1e9;
for (int i = bl[x]; i <= br[x]; i++) {
seq[i] = a[i];
mxval = std::max(mxval, a[i]);
}
static auto modify = [&](const int &p, const int &k, int &tag, int &mxval) {
if (Q[p].r < bl[x] || Q[p].l > br[x])
return ;
// 每次询问的左右两个块要当作单点
if (Q[p].l <= bl[x] && br[x] <= Q[p].r && x != pos[Q[p].l] && x != pos[Q[p].r]) {
tag += k;
mxval += k;
} else {
int mdfL = std::max(bl[x], Q[p].l), mdfR = std::min(br[x], Q[p].r);
mxval = -1e9;
for (int i = bl[x]; i <= br[x]; i++)
seq[i] += tag;
for (int i = mdfL; i <= mdfR; i++)
seq[i] += k;
for (int i = bl[x]; i <= br[x]; i++)
mxval = std::max(mxval, seq[i]);
tag = 0;
}
};
for (int l = 1; l <= m; l++) {
// 把 l 的贡献取消掉
modify(l, 1, tag, mxval);
while (r <= l) {
r++;
if (r != m + 1)
modify(r, -1, tag, mxval);
}
// 如果不是整块, 那么不是这一次要处理的事
if (Q[l].l <= bl[x] && br[x] <= Q[l].r && x != pos[Q[l].l] && x != pos[Q[l].r]) {
while (r <= m && mxval > 0) {
r++;
if (r != m + 1)
modify(r, -1, tag, mxval);
}
delta[l].emplace_back(Q[l].x, 1);
delta[r].emplace_back(Q[l].x, -1);
}
}
}
//}}}
int tr[N];
std::vector<int> single[N];
std::vector<std::pair<int, int>> smdf[N];
inline int lowbit(const int &x) {
return x & -x;
}
inline void add(const int &x, const int &k) {
for (int i = x; i <= m; i += lowbit(i))
tr[i] += k;
}
inline int query(const int &x) {
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i))
ans += tr[i];
return ans;
}
int cnt[N], ans;
/* 无法忘却的记忆与苍蓝之梦 */
int main() {
#ifdef HeratinoNelofus
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m;
for (int i = 1; i <= n; i++)
std::cin >> a[i];
int K = std::__lg(m);
blockInit();
for (int i = 1; i <= m; i++) {
std::cin >> Q[i].l >> Q[i].r >> Q[i].x;
Q[i].t = i;
}
for (int i = 1; i <= bcnt; i++)
solveBlock(i);
//{{{ 提取询问编号
for (int i = 1; i <= m; i++) {
smdf[Q[i].l].emplace_back(i, 1);
smdf[Q[i].r + 1].emplace_back(i, -1);
int pl = pos[Q[i].l];
int pr = pos[Q[i].r];
// 在每个位置上挂上询问编号
if (pl == pr) {
/* 如果是同一个块, 处理自己 */
for (int p = Q[i].l; p <= Q[i].r; p++)
single[p].push_back(i);
} else {
/* 不是同一个块, 处理两端 */
for (int p = Q[i].l; p <= br[pl]; p++)
single[p].push_back(i);
for (int p = bl[pr]; p <= Q[i].r; p++)
single[p].push_back(i);
}
}
//}}}
//{{{计算每个散块询问
for (int i = 1; i <= n; i++) {
for (const auto &[q, k] : smdf[i])
add(q, k);
for (const int &x : single[i]) {
int sum = query(x);
int p = 0;
int csum = 0;
/* BIT 上倍增 */
for (int k = K; k >= 0; k--) {
if (p + (1 << k) <= m) {
int t = csum + tr[p + (1 << k)];
// 只要还能容纳
if (t - sum <= a[i] - 1)
csum = t, p += (1 << k);
}
}
delta[x].emplace_back(Q[x].x, 1);
delta[p + 1].emplace_back(Q[x].x, -1);
}
}
//}}}
for (int i = 1; i <= m; i++) {
for (const auto &[c, k] : delta[i]) {
if (cnt[c] == 1 && k == -1)
ans--;
if (cnt[c] == 0 && k == 1)
ans++;
cnt[c] += k;
}
std::cout << ans << '\n';
}
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: 40ms
memory: 18300kb
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
wrong answer 1225th numbers differ - expected: '1078', found: '1077'
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: 414ms
memory: 235752kb
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:
1 2 3 4 5 4 3 3 3 4 4 4 5 4 4 5 6 7 6 6 7 8 8 4 5 6 7 7 8 9 7 8 9 9 8 8 9 10 10 11 12 12 5 6 7 8 9 4 5 6 7 5 6 7 8 6 7 8 7 7 8 9 9 9 9 10 11 11 11 11 9 10 7 7 6 7 8 6 7 8 8 9 9 10 8 9 9 9 10 10 11 11 12 13 13 14 14 15 16 17 15 16 13 6 7 7 8 9 9 10 10 9 10 10 11 11 11 9 10 10 11 11 12 12 11 8 8 9 10 ...
result:
wrong answer 6th numbers differ - expected: '5', found: '4'
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Memory Limit Exceeded
Test #7:
score: 0
Memory Limit Exceeded
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 11 7 7 8 9 10 10 11 12 11 12 10 9 9 8 7 4 5 6 7 8 9 10 10 11 12 13 13 14 14 15 16 16 17 16 14 11 11 12 13 13 14 14 14 13 14 14 14 14 15 16 17 18 19 19 18 19 18 14 14 14 14 15 12 13 14 15 16 16 17 18 17 18 18 18 18 16 17 17 18 19 19 19 18 19 17 18 19 19 19 19 19 20 21 22...
result:
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Memory Limit Exceeded
Test #9:
score: 0
Memory Limit Exceeded
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 15 16 17 18 19 20 21 22 23 24 24 25 25 26 27 27 28 29 30 29 30 31 30 30 31 30 31 32 33 33 34 35 36 36 37 38 38 37 38 39 40 39 40 41 41 40 40 41 42 43 43 44 45 46 47 48 44 44 43 44 45 44 44 44 45 45 46 47 47 47 48 49 50 49 50 51 52 48 49 50 50 51 52 52 52 52 52 53 ...
result:
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
Memory Limit Exceeded
Test #13:
score: 0
Memory Limit Exceeded
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 27 28 29 30 31 32 33 34 35 36 36 37 38 39 40 41 42 43 43 44 44 45 45 46 47 46 47 47 48 49 48 49 50 51 50 51 52 53 54 55 54 55 55 56 57 58 59 59 60 60 61 61 62 63 64 65 66 67 68 69 70 68 68 69 70 71 72 73 74 73 74 75 76 77 78 79 ...
result:
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%