Submission #57986

# Submission time Handle Problem Language Result Execution time Memory
57986 2018-07-16T15:13:57 Z fredbr Cake (CEOI14_cake) C++17
35 / 100
2000 ms 4428 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 250001;

int n, a;
int v[maxn];
int d[maxn];

vector<int> ans;

inline void f()
{
	ans = {a};

	int l = a-1, r = a+1;
	d[a] = 0;

	for (int i = 1; i < n; i++) {

		if (l > 0 and r <= n) {
			if (v[l] < v[r])
				d[l] = i, l--, ans.push_back(l+1);
			else 
				d[r] = i, r++, ans.push_back(r-1);
		}
		else if (l == 0)
			d[r] = i, r++, ans.push_back(r-1);
		else d[l] = i, l--, ans.push_back(l+1);
	}

	// for (int i : ans)
	// 	cout << i << " ";
	// cout << "\n";
}

inline void fix(int pos, int x, int old)
{
	for (int i = 1; i <= n; i++) {

		if (i == pos) continue;
		if (v[i] <= x and v[i] > old)
			v[i]--;
	}
	v[pos] = x;

	// cout << "\n";
	// for (int i = 1; i <= n; i++)
	// 	cout << v[i] << " ";
	// cout << "\n\n";
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin >> n >> a;

	for (int i = 1; i <= n; i++)
		cin >> v[i];

	f();

	int q;
	cin >> q;

	while (q--) {

		char op;
		cin >> op;

		if (op == 'E') {

			int pos, x;
			cin >> pos >> x;
			fix(pos, n-x+1, v[pos]);
			if (n > 25000) f();
		}
		else {

			int pos;
			cin >> pos;

			if (n < 25000) f();
			cout <<d[pos] << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 26 ms 548 KB Output is correct
5 Correct 469 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2017 ms 772 KB Time limit exceeded
2 Execution timed out 2067 ms 772 KB Time limit exceeded
3 Execution timed out 2077 ms 772 KB Time limit exceeded
4 Execution timed out 2068 ms 772 KB Time limit exceeded
5 Execution timed out 2037 ms 972 KB Time limit exceeded
6 Execution timed out 2070 ms 1100 KB Time limit exceeded
7 Execution timed out 2082 ms 1144 KB Time limit exceeded
8 Execution timed out 2080 ms 1144 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 134 ms 2524 KB Output is correct
2 Correct 86 ms 2524 KB Output is correct
3 Correct 88 ms 2524 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 259 ms 4428 KB Output is correct
6 Correct 216 ms 4428 KB Output is correct
7 Correct 163 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 638 ms 4428 KB Output is correct
2 Correct 1113 ms 4428 KB Output is correct
3 Execution timed out 2061 ms 4428 KB Time limit exceeded
4 Execution timed out 2079 ms 4428 KB Time limit exceeded
5 Correct 1263 ms 4428 KB Output is correct
6 Execution timed out 2055 ms 4428 KB Time limit exceeded
7 Execution timed out 2088 ms 4428 KB Time limit exceeded
8 Execution timed out 2075 ms 4428 KB Time limit exceeded
9 Execution timed out 2062 ms 4428 KB Time limit exceeded
10 Execution timed out 2065 ms 4428 KB Time limit exceeded
11 Execution timed out 2055 ms 4428 KB Time limit exceeded
12 Execution timed out 2082 ms 4428 KB Time limit exceeded
13 Execution timed out 2062 ms 4428 KB Time limit exceeded