QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373031 | #5278. Mex and Cards | FOY# | RE | 4ms | 13184kb | C++23 | 1.4kb | 2024-03-31 23:44:28 | 2024-03-31 23:44:30 |
Judging History
answer
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define int long long
const int mn = 2e5+5;
set<int> indxs[mn];
signed main() {
int n; cin >> n;
vector<int> h(n+1);
for (int i = 0; i < n; i++) {
cin >> h[i];
indxs[h[i]].insert(i);
}
h[n] = -1;
int tot = 0;
int cur = 1e9;
set<int> mins;
mins.insert(n);
for (int i = 0; i < n; i++) {
if (h[i] < cur) {
mins.insert(i);
cur = h[i];
}
tot += cur;
}
cout << tot << endl;
int q; cin >> q;
for (int i = 0; i < q; i++) {
int p, v; cin >> p >> v;
if (p == 2) p = -1;
int nex = *mins.upper_bound(v);
if (mins.count(v)) {
if (p == 1) {
auto fuckingshit = indxs[h[v]].upper_bound(v);
if (fuckingshit != indxs[h[v]].end() && *fuckingshit < nex) {
nex = *fuckingshit;
mins.insert(nex);
}
}
tot += p*(nex-v);
}
if (h[v]+p <= h[nex]) {
if (mins.count(v) == 0) tot += p*(nex-v);
mins.erase(nex);
mins.insert(v);
}
else if (v != 0 && mins.count(v) && h[v] + p >= h[*prev(mins.lower_bound(v))]) {
mins.erase(v);
}
else if (v != 0 && mins.count(v) == 0 && h[v]+p < h[*prev(mins.lower_bound(v))]) {
mins.insert(v);
tot -= nex-v;
}
indxs[h[v]].erase(v);
h[v] += p;
indxs[h[v]].insert(v);
/*for (int j : h) cout << j << ' ';
cout << endl;
for (int j : mins) cout << j << ' ';
cout << endl;*/
cout << tot << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13184kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 7 9 7 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 3ms
memory: 13168kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 12932kb
input:
10 3 8 1 4 10 3 10 9 7 10 20 2 5 1 4 1 2 1 4 1 3 1 3 1 0 2 8 1 5 1 4 1 0 1 3 1 8 1 6 1 4 1 1 1 5 1 9 1 6 2 7
output:
14 14 14 22 22 22 22 24 24 24 24 26 26 26 26 26 26 26 26 26 26
result:
ok 21 numbers
Test #4:
score: 0
Accepted
time: 2ms
memory: 12884kb
input:
10 9 8 7 5 5 4 3 2 1 1 20 2 4 1 8 2 6 1 2 1 2 2 5 2 2 1 0 1 6 1 6 2 9 1 2 2 7 2 8 2 3 1 9 1 7 1 4 2 6 1 7
output:
45 44 45 44 45 45 44 44 45 46 46 45 45 43 43 42 43 44 44 44 45
result:
ok 21 numbers
Test #5:
score: 0
Accepted
time: 4ms
memory: 12900kb
input:
100 969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...
output:
4923 4923 4923 4923 4923 4923 4923 4923 4923 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 ...
result:
ok 1001 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 12940kb
input:
100 994 983 981 980 962 959 959 950 933 887 877 869 841 828 809 807 803 793 789 778 773 772 768 767 765 765 759 757 749 747 742 738 730 724 681 675 656 638 627 626 615 612 593 592 545 543 540 534 531 529 525 520 518 515 512 510 500 494 472 472 432 415 414 411 399 375 350 328 315 307 292 261 258 246 ...
output:
51041 51042 51041 51042 51043 51042 51043 51042 51040 51038 51037 51038 51039 51038 51039 51040 51039 51040 51039 51038 51037 51036 51037 51038 51037 51038 51037 51036 51035 51036 51037 51035 51034 51035 51034 51035 51036 51037 51036 51037 51039 51038 51037 51036 51035 51034 51033 51032 51031 51032 ...
result:
ok 1001 numbers
Test #7:
score: -100
Runtime Error
input:
1000 549187 776775 748956 28001 575132 18015 112492 144497 206885 842190 403842 456113 424268 871411 648618 186832 693358 781526 443190 175126 586343 918652 923262 973941 509929 433837 392849 452585 497398 331180 118333 152788 959909 539943 747365 261855 819641 618091 801231 355664 285761 895793 398...