QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411758 | #8672. 排队 | hcywoi | 0 | 205ms | 22236kb | C++20 | 4.2kb | 2024-05-15 19:14:23 | 2024-05-16 17:37:40 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
template<class Info, class Tag>
struct LazySegmentTree {
int n;
std::vector<Info> info;
std::vector<Tag> tag;
LazySegmentTree() : n(0) {}
LazySegmentTree(int n_, Info v_ = Info()) {
init(n_, v_);
}
template<class T>
LazySegmentTree(std::vector<T> init_) {
init(init_);
}
void init(int n_, Info v_ = Info()) {
init(std::vector(n_, v_));
}
template<class T>
void init(std::vector<T> init_) {
n = init_.size();
info.assign(4 << std::__lg(n), Info());
tag.assign(4 << std::__lg(n), Tag());
std::function<void(int, int, int)> build = [&](int p, int l, int r) {
if (l == r) {
info[p] = init_[l];
return;
}
int m = (l + r) / 2;
build(p * 2, l, m);
build(p * 2 + 1, m + 1, r);
pull(p);
};
build(1, 0, n - 1);
}
void pull(int p) {
info[p] = info[p * 2] + info[p * 2 + 1];
}
void apply(int p, const Tag& v) {
info[p].apply(v);
tag[p].apply(v);
}
void push(int p) {
apply(p * 2, tag[p]);
apply(p * 2 + 1, tag[p]);
tag[p] = Tag();
}
void modify(int p, int l, int r, int x, const Info& v) {
if (l == r) {
info[p] = v;
return;
}
int m = (l + r) / 2;
push(p);
if (x <= m) {
modify(p * 2, l, m, x, v);
} else {
modify(p * 2 + 1, m + 1, r, x, v);
}
pull(p);
}
void modify(int p, const Info& v) {
modify(1, 0, n - 1, p, v);
}
void modify(int p, int l, int r, int x, int y, const Tag& v) {
if (l >= x && r <= y) {
apply(p, v);
return;
}
int m = (l + r) / 2;
push(p);
if (x <= m) {
modify(p * 2, l, m, x, y, v);
}
if (y > m) {
modify(p * 2 + 1, m + 1, r, x, y, v);
}
pull(p);
}
void modify(int l, int r, const Tag& v) {
modify(1, 0, n - 1, l, r, v);
}
Info query(int p, int l, int r, int x, int y) {
if (l >= x && r <= y) {
return info[p];
}
int m = (l + r) / 2;
push(p);
Info info = Info();
if (x <= m) {
info = info + query(p * 2, l, m, x, y);
}
if (y > m) {
info = info + query(p * 2 + 1, m + 1, r, x, y);
}
return info;
}
Info query(int l, int r) {
return query(1, 0, n - 1, l, r);
}
int search(int p, int l, int r, int k) {
if (l == r) {
return l;
}
int m = (l + r) / 2;
push(p);
if (info[p * 2].min <= k) {
return search(p * 2, l, m, k);
} else {
return search(p * 2 + 1, m + 1, r, k);
}
}
int search(int k) {
return search(1, 0, n - 1, k);
}
int search1(int p, int l, int r, int k) {
if (l == r) {
return l;
}
int m = (l + r) / 2;
push(p);
if (info[p * 2 + 1].max >= k) {
return search(p * 2 + 1, m + 1, r, k);
} else {
return search(p * 2, l, m, k);
}
}
int search1(int k) {
return search1(1, 0, n - 1, k);
}
};
struct Tag {
int v = 0;
void apply(const Tag& a) {
v += a.v;
}
};
constexpr int inf = 1E9;
struct Info {
int max = -inf, min = inf;
void apply(const Tag& a) {
max += a.v;
min += a.v;
}
};
Info operator+ (Info a, Info b) {
Info c;
c.max = std::max(a.max, b.max);
c.min = std::min(a.min, b.min);
return c;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<int> l(n), r(n);
for (int i = 0; i < n; i ++ ) {
std::cin >> l[i] >> r[i];
}
std::vector<std::vector<std::pair<int, int>>> qry(n);
for (int i = 0; i < q; i ++ ) {
int l, r;
std::cin >> l >> r;
l --, r -- ;
qry[r].emplace_back(l, i);
}
std::vector<int> ans(q);
LazySegmentTree<Info, Tag> seg(n);
for (int i = 0; i < n; i ++ ) {
seg.modify(i, {0, 0});
int L = seg.search(r[i]), R = seg.search1(l[i]);
std::cout << L << " " << R << "\n";
if (L <= R) {
seg.modify(L, R, {1});
}
for (auto [r, x]: qry[i]) {
ans[x] = seg.query(r, r).max;
}
}
for (int i = 0; i < q; i ++ ) {
std::cout << ans[i] << "\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: 0ms
memory: 3480kb
input:
3 3 0 0 1 2 0 2 1 1 1 3 2 3
output:
0 0 0 0 0 2 1 3 1
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 180ms
memory: 22236kb
input:
200000 200000 3 6 3 3 6 10 1 7 2 7 6 9 4 6 3 4 0 8 0 6 3 5 3 4 1 8 7 8 4 5 0 3 1 5 2 9 1 2 1 2 3 4 5 7 6 10 3 9 4 7 1 6 2 6 1 7 2 5 1 7 6 8 1 1 0 7 7 8 0 9 1 7 3 8 3 7 1 2 4 8 5 6 0 6 5 6 2 7 2 6 0 6 0 6 1 7 2 5 0 3 0 3 7 10 3 8 0 2 3 4 3 7 4 9 0 6 4 7 2 6 8 10 2 10 4 10 3 3 2 6 4 5 3 9 1 8 1 2 2 9 ...
output:
0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 1 0 2 1 3 2 2 2 2 0 3 1 1 2 3 3 4 3 4 0 4 5 5 5 5 4 4 2 4 0 4 2 5 4 5 5 6 5 6 5 7 6 7 5 8 4 6 8 8 6 9 6 6 3 10 7 10 7 9 7 10 11 11 7 10 9 10 10 12 10 11 9 12 11 12 11 13 11 14 11 14 13 14 14 15 15 16 1 12 12 15 16 17 15 15 13 16 8 16 15 18 13 17 16 18 6 13 12 18 13 18 1...
result:
wrong answer 1st numbers differ - expected: '11', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 205ms
memory: 21888kb
input:
200000 200000 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 0 0 9 0 10 0 0 0 0 0 13 0 14 0 0 0 16 0 17 0 18 0 19 0 0 0 21 0 22 0 23 0 0 0 0 0 0 0 0 0 28 0 0 0 30 0 31 0 32 0 33 0 34 0 35 0 0 0 0 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 0 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 0 0 59 0 60 0 0 0 0 ...
output:
0 0 0 1 0 2 0 3 0 4 0 5 0 6 7 7 0 8 0 9 10 10 11 11 0 12 0 13 14 14 0 15 0 16 0 17 0 18 19 19 0 20 0 21 0 22 23 23 24 24 25 25 26 26 0 27 28 28 0 29 0 30 0 31 0 32 0 33 0 34 35 35 36 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 46 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 57 57 0 58 0 ...
result:
wrong answer 1st numbers differ - expected: '19141', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 186ms
memory: 22044kb
input:
200000 200000 0 200000 1 200000 1 200000 0 200000 0 200000 1 200000 1 200000 1 200000 0 200000 1 200000 0 200000 0 200000 1 200000 0 200000 0 200000 0 200000 0 200000 1 200000 0 200000 0 200000 1 200000 0 200000 1 200000 1 200000 1 200000 1 200000 0 200000 0 200000 1 200000 2 200000 1 200000 2 20000...
output:
0 0 0 0 0 1 0 2 0 3 0 3 0 4 0 4 0 5 0 5 0 6 0 7 0 7 0 8 0 9 0 10 0 11 0 11 0 12 0 13 0 13 0 14 0 14 0 15 0 15 0 16 0 17 0 18 0 18 0 18 0 19 0 19 0 20 0 21 0 22 0 21 0 23 0 23 0 24 0 25 0 26 0 26 0 27 0 28 0 29 0 30 0 30 0 31 0 32 0 33 0 34 0 35 0 35 0 36 0 36 0 37 0 38 0 39 0 38 0 40 0 40 0 41 0 42 ...
result:
wrong answer 1st numbers differ - expected: '71224', found: '0'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%