QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373025 | #5278. Mex and Cards | FOY# | WA | 3ms | 12964kb | C++23 | 1.3kb | 2024-03-31 23:40:26 | 2024-03-31 23:40:27 |
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);
}
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: 3ms
memory: 12896kb
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: 0ms
memory: 12964kb
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: -100
Wrong Answer
time: 3ms
memory: 12936kb
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 45 45 46 47 48 47 47 45 45 44 45 46 46 46 47
result:
wrong answer 7th numbers differ - expected: '44', found: '45'