QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120333 | #4270. Double Attendance | bashkort# | Compile Error | / | / | C++20 | 3.8kb | 2023-07-06 16:49:28 | 2024-07-04 00:21:46 |
Judging History
你现在查看的是最新测评结果
- [2024-07-04 00:21:46]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-07-06 16:49:28]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9 + 7;
void ckmax(int &x, int y) {
if (x < y) {
x = y;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n[2], k;
cin >> n[0] >> n[1] >> k;
vector<pair<int, int>> seg[2];
vector<int> yy[2], dp[2], all;
for (int t = 0; t < 2; ++t) {
for (int i = 0; i < n[t]; ++i) {
int l, r;
cin >> l >> r;
if (t == 0 && l == 0) {
was0 = true;
}
seg[t].emplace_back(l, r - 1);
yy[t].push_back(l), yy[t].push_back(r - 1);
}
yy[t].push_back(0);
sort(seg[t].begin(), seg[t].end());
sort(yy[t].begin(), yy[t].end());
yy[t].resize(unique(yy[t].begin(), yy[t].end()) - yy[t].begin());
dp[t].assign(yy[t].size(), -inf);
}
all.resize(yy[0].size() + yy[1].size());
merge(yy[0].begin(), yy[0].end(), yy[1].begin(), yy[1].end(), all.begin());
all.resize(unique(all.begin(), all.end()) - all.begin());
auto in = [&](int t, int i) -> int {
auto it = lower_bound(seg[t].begin(), seg[t].end(), pair<int, int>{i, inf});
if (it == seg[t].begin() || prev(it)->second < i) {
return false;
} else {
return it - seg[t].begin();
}
};
auto isl = [&](int s, int x) {
int i = in(s, x);
return i && seg[s][i - 1].first == x;
};
auto find = [&](int s, int x) -> int {
return lower_bound(yy[s].begin(), yy[s].end(), x) - yy[s].begin();
};
dp[0][0] = isl(0, 0);
int siz[2]{int(size(seg[0])), int(size(seg[1]))};
for (int x : all) {
for (int s = 0; s < 2; ++s) {
int i = find(s, x);
if (i >= size(yy[s]) || yy[s][i] != x) {
continue;
}
int nxt = find(s, x + 1);
if (nxt < siz[s]) {
ckmax(dp[s][nxt], dp[s][i] + isl(s, yy[s][nxt]));
}
nxt = find(s ^ 1, x + k);
if (nxt < siz[s ^ 1]) {
ckmax(dp[s ^ 1][nxt], dp[s][i] + isl(s ^ 1, yy[s ^ 1][nxt]));
}
int cnt = 0;
for (int t = 1; ; ++t) {
int ns = s ^ (t & 1);
int nx = x + k * t;
if (!in(ns, nx)) {
break;
} else {
cnt += 1;
}
}
if (cnt > 0) {
int del = cnt % 2 == 0;
if (del) {
cnt -= 1;
}
int nx = x + k * cnt;
int p = in(s ^ 1, nx);
assert(p > 0);
p -= 1;
ckmax(dp[s ^ 1][find(s ^ 1, seg[s ^ 1][p].second)], dp[s][i] + cnt);
if (del) {
cnt += 1;
}
}
if (cnt > 1) {
int del = cnt % 2 == 1;
if (del) {
cnt -= 1;
}
int nx = x + k * cnt;
int p = in(s, nx);
assert(p > 0);
p -= 1;
ckmax(dp[s][find(s, seg[s][p].second)], dp[s][i] + cnt);
if (del) {
cnt += 1;
}
}
for (int c : {cnt, cnt + 1}) {
int ns = s ^ (c & 1);
int ni = find(ns, x + c * k);
if (ni < siz[ns]) {
ckmax(dp[ns][ni], dp[s][i] + c);
}
}
}
}
int ans = max(*max_element(dp[0].begin(), dp[0].end()), *max_element(dp[1].begin(), dp[1].end()));
cout << ans << '\n';
return 0;
}
详细
answer.code: In function ‘int main()’: answer.code:29:17: error: ‘was0’ was not declared in this scope 29 | was0 = true; | ^~~~