QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411750 | #8672. 排队 | hcywoi | Compile Error | / | / | C++14 | 4.1kb | 2024-05-15 19:09:08 | 2024-05-16 17:37:34 |
Judging History
你现在查看的是最新测评结果
- [2024-05-16 17:37:34]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-05-15 19:09:09]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-05-15 19:09:08]
- 提交
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);
}
};
// i v_i <= r[i]
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, {0, 0});
for (int i = 0; i < n; i ++ ) {
int L = seg.search(r[i]), R = seg.search(l[i]);
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;
}
詳細信息
answer.code: In member function ‘void LazySegmentTree<Info, Tag>::init(int, Info)’: answer.code:19:25: error: missing template arguments before ‘(’ token 19 | init(std::vector(n_, v_)); | ^ answer.code: In function ‘int main()’: answer.code:202:27: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 202 | for (auto [r, x]: qry[i]) { | ^