QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322054 | #8162. 读书 | HaccerKat# | 100 ✓ | 181ms | 13392kb | C++20 | 1.7kb | 2024-02-06 08:44:43 | 2024-07-04 03:22:44 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#ifdef DEBUG
#define dbg(x) cout << (#x) << " = " << (x) << "\n";
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair<int, int> pi;
const int N = 500005;
const int inf = 1e9;
int n, m, k, qq, d;
int a[N], t[N * 4];
void build(int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int mid = (tl + tr) / 2;
build(v * 2, tl, mid);
build(v * 2 + 1, mid + 1, tr);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
void update(int p, int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
t[v] = inf;
return;
}
int mid = (tl + tr) / 2;
if (p <= mid) update(p, v * 2, tl, mid);
else update(p, v * 2 + 1, mid + 1, tr);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
int findfirst(int p, int x, int v = 1, int tl = 0, int tr = n - 1) {
if (tr <= p || t[v] > x) return -1;
if (tl == tr) return tl;
int mid = (tl + tr) / 2;
int L = findfirst(p, x, v * 2, tl, mid);
if (L != -1) return L;
return findfirst(p, x, v * 2 + 1, mid + 1, tr);
}
void solve() {
cin >> d >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
build();
int out = 0, p = -1, cur = 0;
while (cur < n) {
int px = findfirst(p, cur);
if (px == -1 && p == -1) {
cout << "-1\n";
return;
}
if (px == -1) out++, p = -1;
else {
p = px, cur++;
update(p);
}
}
cout << out + 1 << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 5740kb
input:
1 10 4 0 8 6 1 0 6 1 9 4
output:
3
result:
ok single line: '3'
Subtask #2:
score: 10
Accepted
Test #2:
score: 10
Accepted
time: 0ms
memory: 5656kb
input:
2 500 57 132 248 138 439 28 343 346 384 292 360 137 360 105 104 313 443 347 98 162 351 20 348 169 167 347 413 310 186 163 308 416 112 434 76 338 491 204 418 53 469 429 23 489 274 55 400 2 32 271 279 306 23 337 15 321 58 82 253 99 486 329 437 215 70 183 321 16 363 279 166 384 384 236 390 77 77 157 18...
output:
178
result:
ok single line: '178'
Subtask #3:
score: 20
Accepted
Test #3:
score: 20
Accepted
time: 2ms
memory: 7724kb
input:
3 5000 1733 126 257 3424 70 247 1945 4541 2817 994 498 702 606 1475 2918 3930 264 1206 3188 165 2761 835 244 1200 255 907 663 252 630 2025 1471 279 2720 379 963 1028 2945 1214 2185 987 1093 120 198 4497 223 237 1002 663 247 260 861 273 1419 3744 414 2756 2692 427 664 1652 2034 3370 2391 1623 1426 43...
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 2ms
memory: 5680kb
input:
4 5000 4061 3515 2056 3429 945 4821 3948 2292 3933 4426 1012 2000 4470 466 954 3591 446 475 876 2101 2669 2296 4839 1974 4100 287 3655 2735 571 3779 2668 3269 4199 4724 278 1035 2164 2422 147 3459 3202 3503 4226 239 3345 2379 3122 1631 3094 4900 4395 2174 4813 596 2149 1065 3297 921 4705 3995 2240 4...
output:
1767
result:
ok single line: '1767'
Subtask #4:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 21ms
memory: 4996kb
input:
5 100000 140 46422 12955 3372 72174 1099 31072 32714 2046 55875 1642 3142 1979 19740 36555 46665 14527 11836 64389 4430 11526 49406 16966 23379 34626 2042 55570 1868 3262 85405 28592 14013 18056 58942 7519 50919 19915 1468 22065 19323 25211 457 8403 18265 3833 18 18210 64768 21054 90342 30419 15893 ...
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 27ms
memory: 6768kb
input:
6 100000 67718 10449 9663 49073 12246 46153 56019 49346 40211 13623 51158 38874 59261 44909 66318 99521 39592 75296 97256 44321 66633 98765 6549 99181 44933 82518 65816 46730 76234 64887 68548 37162 42292 75158 42805 87975 93041 65385 87895 2698 31512 46968 34332 4726 38971 70418 23634 32722 86787 3...
output:
35203
result:
ok single line: '35203'
Subtask #5:
score: 40
Accepted
Test #7:
score: 40
Accepted
time: 119ms
memory: 13344kb
input:
7 500000 229944 62332 282919 56524 48179 332589 277727 245764 767 3314 75837 14427 123577 216331 19161 72607 45790 75277 39385 52598 79090 297482 270468 82100 141087 23861 23481 145596 87436 43872 284101 12268 349667 27796 7137 356461 22114 73926 126650 185604 60160 185737 3089 122228 90810 137323 4...
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 175ms
memory: 13392kb
input:
8 500000 399080 111590 74185 271517 211645 92689 235442 224988 429346 305747 210812 109561 302177 431121 238657 294096 478106 485684 423769 477450 117978 299550 205849 153266 374890 316928 408757 451498 435782 389366 336332 330177 80616 208173 359638 333047 33350 210212 124057 105060 456223 125636 3...
output:
24666
result:
ok single line: '24666'
Test #9:
score: 0
Accepted
time: 181ms
memory: 13384kb
input:
9 500000 397390 290173 220648 370554 119384 314070 4814 119020 277046 218030 334349 261617 145850 405658 96019 110171 111452 238639 314886 309158 313747 322602 245226 103999 380687 54402 139646 208518 90569 362316 27917 275112 334154 117582 377027 431321 224291 46182 195910 304013 213812 156536 4876...
output:
175554
result:
ok single line: '175554'
Test #10:
score: 0
Accepted
time: 180ms
memory: 11344kb
input:
10 500000 411336 280958 122810 446917 29910 58720 307226 263466 410288 269703 167310 63052 193571 432592 155104 392083 17921 56911 344980 101285 464565 362607 44415 40583 346210 370803 150886 52214 303782 119800 57384 395922 140020 350409 437814 385131 181473 417297 496273 10076 305702 316161 392544...
output:
250188
result:
ok single line: '250188'