QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563080 | #7969. 套娃 | Elegia | AC ✓ | 119ms | 22272kb | C++23 | 3.4kb | 2024-09-14 02:27:18 | 2024-09-14 02:27:20 |
Judging History
answer
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <bitset>
#include <numeric>
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
typedef unsigned long long ull;
const int _ = 100005;
int N;
int a[_], cnt[_];
std::vector<int> positions[_];
std::vector<std::pair<int, int>> events[_];
std::map<int, int> stair;
namespace SEGT {
int tag[1 << 18], min[1 << 18];
void update(int o) { min[o] = std::min(min[o << 1], min[o << 1 | 1]); }
void apply(int o, int x) { tag[o] += x; min[o] += x; }
void pushdown(int o) {
apply(o << 1, tag[o]);
apply(o << 1 | 1, tag[o]);
tag[o] = 0;
}
void change(int o, int l, int r, int ql, int qr, int x) {
// std::cerr << "CHANGE " << o << ' ' << l << ' ' << r << ' ' << ql << ' ' << qr << ' ' << x << '\n';
if (ql <= l && r <= qr) {
apply(o, x);
return;
}
pushdown(o);
int mid = (l + r) >> 1;
if (ql <= mid) change(o << 1, l, mid, ql, qr, x);
if (qr > mid) change(o << 1 | 1, mid + 1, r, ql, qr, x);
update(o);
}
int query(int o, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return min[o];
pushdown(o);
int mid = (l + r) >> 1;
int res = std::numeric_limits<int>::max();
if (ql <= mid) res = std::min(res, query(o << 1, l, mid, ql, qr));
if (qr > mid) res = std::min(res, query(o << 1 | 1, mid + 1, r, ql, qr));
return res;
}
}
void insert(int x, int y) {
// std::cerr << "tring insert " << x << ", " << y << '\n';
auto it = stair.lower_bound(y);
if (it->second <= x) return;
if (it->first != y) --it;
while (it->second >= x) {
int delt = it->first - prev(it)->first;
SEGT::change(1, 1, N, it->second, next(it)->second - 1, -delt);
stair.erase(it--);
}
it = stair.insert(std::make_pair(y, x)).first;
int delt = y - prev(it)->first;
// std::cerr << "CHG " << x << ", " << (next(it)->second - 1) << '\n';
SEGT::change(1, 1, N, x, (++it)->second - 1, delt);
}
int bound_pos(int x) { // first pos < x
auto it = stair.lower_bound(x);
return it->second - 1;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
std::cin >> N;
for (int i = 1; i <= N; ++i) std::cin >> a[i];
for (int i = 0; i != N; ++i) positions[i].push_back(0);
for (int i = 1; i <= N; ++i) positions[a[i]].push_back(i);
for (int i = 0; i != N; ++i) positions[i].push_back(N + 1);
for (int i = 0; i <= N + 2; ++i) stair.insert(std::make_pair(i, i));
for (int i = 0; i != N; ++i) {
for (int j = 0; j != positions[i].size() - 1; ++j) {
int l = positions[i][j], r = positions[i][j + 1];
int pos = bound_pos(r);
// std::cerr << l << " " << r << ": " << pos << '\n';
if (pos > l) {
int u = r - l - 1;
int d = SEGT::query(1, 1, N, l + 1, pos) + 1;
events[d].push_back(std::make_pair(i, 1));
events[u + 1].push_back(std::make_pair(i, -1));
// std::cerr << i << ": " << d << " ~ " << u << '\n';
}
insert(l + 1, r);
}
}
std::set<int> excl;
for (int i = 0; i <= N; ++i) excl.insert(i);
for (int i = 1; i <= N; ++i) {
for (auto &e : events[i]) {
if (e.second == 1) {
if (cnt[e.first]++ == 0) excl.erase(e.first);
} else {
if (--cnt[e.first] == 0) excl.insert(e.first);
}
}
std::cout << *excl.begin() << " \n"[i == N];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
input:
6 0 0 0 1 2 3
output:
2 3 4 0 0 0
result:
ok single line: '2 3 4 0 0 0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
100 0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1
output:
2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok single line: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #3:
score: 0
Accepted
time: 72ms
memory: 17480kb
input:
100000 127 145 474 139 36 135 75 670 76 433 206 214 283 56 214 440 147 280 244 190 181 565 31 550 261 93 526 404 125 390 17 552 5 364 53 337 52 506 277 279 15 248 46 61 826 69 166 297 171 289 150 175 111 151 317 342 166 13 199 152 308 19 156 347 205 166 45 115 177 235 422 425 109 4 658 232 347 370 4...
output:
2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...
result:
ok single line: '2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #4:
score: 0
Accepted
time: 69ms
memory: 18844kb
input:
100000 360 34 204 156 183 404 21 3 20 122 170 193 347 144 51 464 94 265 190 88 284 437 538 392 661 397 839 208 83 191 42 16 194 515 374 53 617 502 307 504 348 175 219 63 2 130 289 223 135 440 284 189 104 142 87 117 316 218 301 14 87 405 293 489 763 197 678 196 173 96 257 17 190 525 243 161 220 178 8...
output:
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...
result:
ok single line: '2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #5:
score: 0
Accepted
time: 77ms
memory: 17592kb
input:
100000 322 408 29 271 168 161 265 412 230 177 325 60 331 226 298 143 343 83 274 706 47 234 287 46 329 248 174 351 235 38 172 171 251 355 274 307 468 11 222 309 666 137 18 440 1209 7 103 354 496 336 183 602 240 316 442 253 32 486 308 18 115 125 110 65 268 502 148 793 91 759 313 269 31 63 250 90 143 6...
output:
2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 ...
result:
ok single line: '2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #6:
score: 0
Accepted
time: 62ms
memory: 17644kb
input:
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Test #7:
score: 0
Accepted
time: 119ms
memory: 22272kb
input:
100000 0 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok single line: '2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0'
Test #8:
score: 0
Accepted
time: 97ms
memory: 22056kb
input:
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok single line: '2 3 4 5 6 7 8 9 10 11 12 13 14...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'