QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#261553 | #7755. Game on a Forest | SSH | Compile Error | / | / | C++17 | 3.5kb | 2023-11-22 23:26:30 | 2023-11-22 23:26:30 |
Judging History
answer
using i64 = long long;
// 动态开点线段树
struct Node {
int val = 0, tag = 0;
Node *l = nullptr;
Node *r = nullptr;
};
void up(Node *p) {
if (!p->l)
p->val = p->r->val;
else if (!p->r)
p->val = p->l->val;
else
p->val = p->l->val + p->r->val;
}
void down(Node *p, int l, int r) {
if (p->tag == 0)
return;
int mid = l + r >> 1;
if (!p->l)
p->l = new Node();
if (!p->r)
p->r = new Node();
int b = p->tag;
p->l->val += b * (mid - l + 1);
p->r->val += b * (r - mid);
p->l->tag += b;
p->r->tag += b;
p->tag = 0;
}
// 区间加 1
void modify(Node *&p, int l, int r, int tl, int tr) {
if (!p)
p = new Node();
if (tl <= l and r <= tr) {
p->val += r - l + 1;
p->tag++;
return;
}
down(p, l, r);
int mid = l + r >> 1;
if (tl <= mid)
modify(p->l, l, mid, tl, tr);
if (mid < tr)
modify(p->r, mid + 1, r, tl, tr);
up(p);
}
// 区间求和
int get(Node *p, int l, int r, int tl, int tr) {
if (!p)
return 0;
if (tl <= l and r <= tr) {
return p->val;
}
down(p, l, r);
int mid = l + r >> 1, ans = 0;
if (tl <= mid)
ans = get(p->l, l, mid, tl, tr);
if (mid < tr)
ans += get(p->r, mid + 1, r, tl, tr);
return ans;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, k;
std::cin >> n >> m >> k;
std::vector<std::array<int, 3>> wall(k);
std::vector<int> b = {1, m};
for (auto &[xl, xr, y] : wall) {
std::cin >> xl >> xr >> y;
b.push_back(y);
if (y != 1)
b.push_back(y - 1);
}
std::sort(b.begin(), b.end());
b.erase(std::unique(b.begin(), b.end()), b.end());
auto find = [&](int x) {
return std::lower_bound(b.begin(), b.end(), x) - b.begin();
}; // 离散化三件套, 把 y 给离散一下
std::vector wallArr(b.size(), std::vector<std::pair<int, int>>());
for (auto [xl, xr, y] : wall) {
wallArr[find(y)].push_back({xl, xr});
}
i64 nodeCnt = 1ll * n * m, edgeCnt = 2ll * n * m - n - m;
// 点数, 边数
Node *rt = new Node(); // 开个线段树
for (int y = 0; y < b.size(); y++) {
if (!wallArr[y].empty()) {
std::sort(wallArr[y].begin(), wallArr[y].end());
for (int i = 0; i < wallArr[y].size(); i++) {
auto [l, r] = wallArr[y][i];
nodeCnt -= r - l + 1;
edgeCnt += get(rt, 1, n, l, r) - (r - l + 2);
edgeCnt -= 2 * (r - l + 1);
// 墙在下底
if (y == 0)
edgeCnt += r - l + 1;
// 墙在上顶
if (y + 1 == b.size())
edgeCnt += r - l + 1;
// 俩墙左右贴着
if (i and wallArr[y][i - 1].second + 1 == l)
edgeCnt++;
// 墙贴着左侧
if (i == 0 and l == 1)
edgeCnt++;
// 墙贴着右侧
if (i + 1 == wallArr[y].size() and r == n)
edgeCnt++;
}
}
rt = new Node(); // 开个新的线段树
for (auto [l, r] : wallArr[y]) {
modify(rt, 1, n, l, r);
}
}
std::cout << (edgeCnt + 1 == nodeCnt ? "YES" : "NO");
}
詳細信息
answer.code: In function ‘int main()’: answer.code:75:10: error: ‘std::ios_base’ has not been declared 75 | std::ios_base::sync_with_stdio(false); | ^~~~~~~~ answer.code:76:10: error: ‘cin’ is not a member of ‘std’ 76 | std::cin.tie(nullptr); | ^~~ answer.code:1:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? +++ |+#include <iostream> 1 | using i64 = long long; answer.code:79:10: error: ‘cin’ is not a member of ‘std’ 79 | std::cin >> n >> m >> k; | ^~~ answer.code:79:10: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? answer.code:81:10: error: ‘vector’ is not a member of ‘std’ 81 | std::vector<std::array<int, 3>> wall(k); | ^~~~~~ answer.code:1:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? +++ |+#include <vector> 1 | using i64 = long long; answer.code:81:22: error: ‘array’ is not a member of ‘std’ 81 | std::vector<std::array<int, 3>> wall(k); | ^~~~~ answer.code:1:1: note: ‘std::array’ is defined in header ‘<array>’; did you forget to ‘#include <array>’? +++ |+#include <array> 1 | using i64 = long long; answer.code:81:28: error: expected primary-expression before ‘int’ 81 | std::vector<std::array<int, 3>> wall(k); | ^~~ answer.code:82:10: error: ‘vector’ is not a member of ‘std’ 82 | std::vector<int> b = {1, m}; | ^~~~~~ answer.code:82:10: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? answer.code:82:17: error: expected primary-expression before ‘int’ 82 | std::vector<int> b = {1, m}; | ^~~ answer.code:83:30: error: ‘wall’ was not declared in this scope 83 | for (auto &[xl, xr, y] : wall) { | ^~~~ answer.code:84:14: error: ‘cin’ is not a member of ‘std’ 84 | std::cin >> xl >> xr >> y; | ^~~ answer.code:84:14: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? answer.code:85:9: error: ‘b’ was not declared in this scope 85 | b.push_back(y); | ^ answer.code:90:10: error: ‘sort’ is not a member of ‘std’ 90 | std::sort(b.begin(), b.end()); | ^~~~ answer.code:90:15: error: ‘b’ was not declared in this scope 90 | std::sort(b.begin(), b.end()); | ^ answer.code:91:18: error: ‘unique’ is not a member of ‘std’ 91 | b.erase(std::unique(b.begin(), b.end()), b.end()); | ^~~~~~ answer.code: In lambda function: answer.code:93:21: error: ‘lower_bound’ is not a member of ‘std’ 93 | return std::lower_bound(b.begin(), b.end(), x) - b.begin(); | ^~~~~~~~~~~ answer.code: In function ‘int main()’: answer.code:96:10: error: ‘vector’ is not a member of ‘std’ 96 | std::vector wallArr(b.size(), std::vector<std::pair<int, int>>()); | ^~~~~~ answer.code:96:10: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? answer.code:97:29: error: ‘wall’ was not declared in this scope 97 | for (auto [xl, xr, y] : wall) { | ^~~~ answer.code:98:9: error: ‘wallArr’ was not declared in this scope 98 | wallArr[find(y)].push_back({xl, xr}); | ^~~~~~~ answer.code:107:14: error: ‘wallArr’ was not declared in this scope 107 | if (!wallArr[y].empty()) { | ^~~~~~~ answer.code:108:18: error: ‘sort’ is not a member of ‘std’ 108 | std::sort(wallArr[y].begin(), wallArr[y].end()); | ^~~~ answer.code:139:28: error: ‘wallArr’ was not declared in this scope 139 | for (auto [l, r] : wallArr[y]) { | ^~~~~~~ answer.code:144:10: error: ‘cout’ is not a member of ‘std’ 144 | std::cout << (edgeCnt + 1 == nodeCnt ? "YES" : "NO"); | ^~~~ answer.code:144:10: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?