Submission #1106376

# Submission time Handle Problem Language Result Execution time Memory
1106376 2024-10-30T07:04:05 Z stdfloat Simple game (IZhO17_game) C++17
22 / 100
1000 ms 4856 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = (int)1e6 + 1;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n, q;
	cin >> n >> q;

	vector<int> a(n);
	for (auto &i : a)
		cin >> i;

	if (n <= (int)1e3) {
		while (q--) {
			int tp, x;
			cin >> tp >> x;

			if (tp == 1) {
				int vl;
				cin >> vl;

				a[--x] = vl;
			}
			else {
				int cnt = 0;
				for (int i = 0; i + 1 < n; i++)
					cnt += (min(a[i], a[i + 1]) < x && x < max(a[i], a[i + 1]));

				cout << cnt << '\n';
			}
		}
		return 0;
	}

	vector<int> cnt(N);
	for (int i = 0; i + 1 < n; i++)
		cnt[min(a[i], a[i + 1])]++;
	for (int i = N - 2; i >= 0; i--)
		cnt[i] += cnt[i - 1];

	while (q--) {
		int tp, x;
		cin >> tp >> x;

		int y = -1, cntx = 0;
		for (int i = 0; i < n; i++) {
			if (x < a[i]) {
				cntx += (i != n - 1);
				if ((y == -1 || a[i] < a[y])) y = i;
			}
		}
	
		cout << (y == -1 ? 0 : (x < a[n - 1]) + ((cntx - cnt[a[y]]) << 1)) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Execution timed out 1071 ms 4856 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Execution timed out 1071 ms 4856 KB Time limit exceeded
9 Halted 0 ms 0 KB -