QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120351 | #4270. Double Attendance | bashkort# | 0 | 1ms | 3604kb | C++20 | 3.9kb | 2023-07-06 16:58:31 | 2024-07-04 00:21:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 2e9 + 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;
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(yy[0])), int(size(yy[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] + 1);
}
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;
assert(yy[s ^ 1][find(s ^ 1, nx)] == seg[s ^ 1][p].second);
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;
assert(yy[s][find(s, nx)] == seg[s][p].second);
ckmax(dp[s][find(s, seg[s][p].second)], dp[s][i] + cnt);
if (del) {
cnt += 1;
}
}
for (int c : {cnt - 1, cnt, cnt + 1}) {
if (c <= 0) {
continue;
}
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;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 5
Accepted
time: 1ms
memory: 3484kb
input:
3 1 8 10 20 100 101 20 21 15 25
output:
3
result:
ok single line: '3'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3536kb
input:
1 5 3 1 100 1 2 2 3 3 4 4 5 5 6
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Runtime Error
input:
10 10 5 4 9 43 48 69 70 70 72 52 67 75 83 100 103 103 1501 10 27 28 40 5 7 27 29 30 39 40 42 42 45 67 80 0 5 45 59 10 20 22 23
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #104:
score: 6
Accepted
time: 0ms
memory: 3604kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #105:
score: 6
Accepted
time: 0ms
memory: 3532kb
input:
1 2000 2 999999996 1000000000 336 337 502 503 1906 1907 963 964 1351 1352 1795 1796 1510 1511 304 305 1930 1931 1735 1736 1469 1470 338 339 813 814 182 183 209 210 321 322 849 850 721 722 394 395 889 890 1758 1759 1440 1441 560 561 1470 1471 1916 1917 793 794 1366 1367 158 159 1602 1603 214 215 1119...
output:
2000
result:
ok single line: '2000'
Test #106:
score: 0
Runtime Error
input:
2000 2000 249875 608195750 608695500 88455750 88955500 579210250 579710000 817091250 817591000 527736000 528235750 52473750 52973500 89955000 90454750 184407750 184907500 668165750 668665500 24487750 24987500 466266750 466766500 471764000 472263750 212393750 212893500 250874500 251374250 939530000 9...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%