QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373018#5278. Mex and CardsFOY#WA 1ms3584kbC++23817b2024-03-31 23:17:402024-03-31 23:17:41

Judging History

你现在查看的是最新测评结果

  • [2024-03-31 23:17:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-03-31 23:17:40]
  • 提交

answer

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> h(n+1);
	for (int i = 0; i < n; i++) {
		cin >> h[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)) {
			tot += p*(nex-v);
		}

		if (h[v]+p <= h[nex]) {
			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);
		}
		h[v] += p;
		cout << tot << endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3504kb

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: 3472kb

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

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: 0ms
memory: 3584kb

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
45
47
46
47
47
47
47
48
52
56
56
56
56
56
55
55
55
55
55
55

result:

wrong answer 2nd numbers differ - expected: '44', found: '45'