QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212502 | #1977. The Last Supper | Zanite# | TL | 548ms | 7616kb | C++17 | 2.0kb | 2023-10-13 16:35:45 | 2023-10-13 16:35:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define fi first
#define se second
#define All(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << (x) << '\n';
const int iINF = 1'000'000'000;
const ll INF = 1'000'000'000'000'000'000;
using Segment = pii;
const int maxN = 100'023;
int N, M, Q, pf[maxN];
vector<Segment> seg[maxN];
vector<pii> que;
bool ans[maxN];
char buf;
Segment unionSeg(Segment &a, Segment &b) {
return {min(a.fi, b.fi), max(a.se, b.se)};
}
vector<Segment> mergeSeg(vector<Segment> &a, vector<Segment> &b) {
vector<Segment> c;
for (auto i : a) c.push_back(i);
for (auto i : b) c.push_back(i);
sort(All(c));
vector<Segment> ret;
for (auto s : c) {
while (!ret.empty() && (ret.back().se >= s.fi)) {
s = unionSeg(s, ret.back());
ret.pop_back();
}
ret.push_back(s);
}
return ret;
}
int querySeg(vector<Segment> &v) {
int ret = 0;
for (auto [l, r] : v) ret += pf[r] - pf[l-1];
return ret;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M >> Q;
for (int x, i = 1; i <= M; i++) {
cin >> x;
pf[x] = 1;
}
for (int x, d, i = 1; i <= Q; i++) {
cin >> x >> buf;
if (buf == 'L') d = 1;
else d = -1;
que.push_back({x, d});
}
for (int i = 1; i <= N; i++) pf[i] += pf[i-1];
for (int i = 1; i <= N; i++) {
seg[i].push_back({i, i});
if (querySeg(seg[i]) == M) ans[i] = true;
}
reverse(All(que));
for (auto &[x, d] : que) {
int y = x + d;
if (y == 0) y = N;
if (y == N+1) y = 1;
seg[x] = mergeSeg(seg[x], seg[y]);
if (querySeg(seg[x]) == M) ans[x] = true;
}
for (int i = 1; i <= N; i++) {
if (ans[i]) cout << i << " ";
}
cout << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5960kb
input:
3 1 3 2 1 L 2 L 3 L
output:
1 2
result:
ok single line: '1 2 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 6144kb
input:
3 2 2 2 3 1 R 3 R
output:
1 3
result:
ok single line: '1 3 '
Test #3:
score: 0
Accepted
time: 548ms
memory: 7616kb
input:
400 260 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 226 227 228 229 230 231 232 233 234 235...
output:
346 347 348 349 350 351 352 353 354 355 356 357 358
result:
ok single line: '346 347 348 349 350 351 352 353 354 355 356 357 358 '
Test #4:
score: 0
Accepted
time: 193ms
memory: 7344kb
input:
1000 8 100000 101 113 120 152 156 164 177 191 429 L 897 L 63 L 470 L 95 R 610 L 417 R 1 L 958 R 671 R 931 R 171 R 512 R 935 L 75 L 298 R 538 R 830 R 580 L 986 L 377 L 232 R 861 L 32 L 113 R 852 R 202 L 946 R 784 L 213 L 56 L 108 L 667 L 234 L 653 R 828 R 175 L 886 L 5 L 350 L 304 R 600 L 916 R 912 R...
output:
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
result:
ok single line: '135 136 137 138 139 140 141 14...51 152 153 154 155 156 157 158 '
Test #5:
score: -100
Time Limit Exceeded
input:
8191 2043 49152 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...