Submission #57983

# Submission time Handle Problem Language Result Execution time Memory
57983 2018-07-16T15:10:14 Z fredbr Cake (CEOI14_cake) C++17
35 / 100
2000 ms 4672 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]);
			f();
		}
		else {

			int pos;
			cin >> pos;

			cout <<d[pos] << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 408 KB Output is correct
4 Correct 26 ms 540 KB Output is correct
5 Correct 402 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2037 ms 1108 KB Time limit exceeded
2 Execution timed out 2072 ms 1108 KB Time limit exceeded
3 Execution timed out 2087 ms 1108 KB Time limit exceeded
4 Execution timed out 2079 ms 1108 KB Time limit exceeded
5 Execution timed out 2065 ms 1132 KB Time limit exceeded
6 Execution timed out 2088 ms 1132 KB Time limit exceeded
7 Execution timed out 2052 ms 1132 KB Time limit exceeded
8 Execution timed out 2067 ms 1132 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 191 ms 2676 KB Output is correct
2 Correct 99 ms 2676 KB Output is correct
3 Correct 103 ms 2676 KB Output is correct
4 Correct 3 ms 2676 KB Output is correct
5 Correct 204 ms 4600 KB Output is correct
6 Correct 237 ms 4672 KB Output is correct
7 Correct 182 ms 4672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 717 ms 4672 KB Output is correct
2 Correct 1109 ms 4672 KB Output is correct
3 Execution timed out 2072 ms 4672 KB Time limit exceeded
4 Execution timed out 2086 ms 4672 KB Time limit exceeded
5 Correct 1361 ms 4672 KB Output is correct
6 Execution timed out 2044 ms 4672 KB Time limit exceeded
7 Execution timed out 2076 ms 4672 KB Time limit exceeded
8 Execution timed out 2067 ms 4672 KB Time limit exceeded
9 Execution timed out 2069 ms 4672 KB Time limit exceeded
10 Execution timed out 2076 ms 4672 KB Time limit exceeded
11 Execution timed out 2086 ms 4672 KB Time limit exceeded
12 Execution timed out 2070 ms 4672 KB Time limit exceeded
13 Execution timed out 2067 ms 4672 KB Time limit exceeded