# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
285911 |
2020-08-29T18:14:06 Z |
caoash |
Cake (CEOI14_cake) |
C++14 |
|
2000 ms |
5880 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
template<class T, int SZ> struct Seg{
T tree[4*SZ];
T merge(T a, T b){
return max(a, b);
}
void update(int v, int l, int r, int i, T x) {
if (i > r || i < l) {
return;
} else if (l == r) {
tree[v] = x;
} else {
int m = (l + r) / 2;
update(2 * v + 1, l, m, i, x);
update(2 * v + 2, m + 1, r, i, x);
tree[v] = merge(tree[2 * v + 1], tree[2 * v + 2]);
}
}
T query(int v, int l, int r, int ql, int qr) {
if (l > qr || r < ql) {
return 0;
} else if (l >= ql && r <= qr) {
return tree[v];
} else {
int m = (l + r) / 2;
T a = query(2 * v + 1, l, m, ql, qr);
T b = query(2 * v + 2, m + 1, r, ql, qr);
return merge(a,b);
}
}
};
const int MX = 200005;
int pos[MX];
Seg<int, MX> vals;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, a; cin >> n >> a;
a--;
vi d(n);
for (int i = 0; i < n; i++) {
cin >> d[i];
pos[d[i]] = i;
vals.update(0, 0, n - 1, i, d[i]);
}
/*
cout << "vals: " << '\n';
for (int i = 0; i < n; i++) {
cout << vals.query(0, 0, n - 1, i, i) << " ";
}
cout << '\n';
*/
int q; cin >> q;
vector<pi> top;
for (int i = max(1, n - 9); i <= n; i++) {
top.pb(mp(i, pos[i]));
}
while(q--) {
char qt; cin >> qt;
if (qt == 'E') {
int i, e; cin >> i >> e;
i--;
vector<pi> order;
/*
cout << "TOP: " << '\n';
for (int x : top) {
cout << x << " ";
}
cout << '\n';
*/
for (int j = 0; j < e - 1; j++) {
if (top.back().s != i) {
int v = top.back().f; int p = top.back().s;
order.pb(mp(v + 1, p));
vals.update(0, 0, n - 1, p, v + 1);
d[p] = v + 1;
}
else {
j--;
}
top.pop_back();
}
int prev = d[i];
// cout << "prev: " << prev << endl;
d[i] = top.back().f + 1;
vals.update(0, 0, n - 1, i, top.back().f + 1);
order.pb(mp(top.back().f + 1, i));
while (!top.empty()) {
if(top.back().f != prev) order.pb(mp(top.back().f, top.back().s));
top.pop_back();
}
reverse(all(order));
for (pi x : order) {
top.pb(x);
}
/*
cout << "vals: " << '\n';
for (int j = 0; j < n; j++) {
cout << d[j] << " ";
}
cout << '\n';
*/
}
else {
int x; cin >> x;
x--;
if (x == a) {
cout << 0 << '\n';
continue;
}
int best = 0;
if (x < a) best = vals.query(0, 0, n - 1, x, a - 1);
else if (x > a) best = vals.query(0, 0, n - 1, a + 1, x);
if (x < a) {
int lo = a + 1; int hi = n - 1;
int ans = n;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (vals.query(0, 0, n - 1, a + 1, mid) > best) {
ans = mid;
hi = mid - 1;
}
else {
lo = mid + 1;
}
}
cout << (ans - x - 1) << '\n';
}
else {
int lo = 0; int hi = a - 1;
int ans = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (vals.query(0, 0, n - 1, mid, a - 1) > best) {
ans = mid;
lo = mid + 1;
}
else {
hi = mid - 1;
}
}
cout << (x - ans - 1) << '\n';
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
32 ms |
384 KB |
Output is correct |
5 |
Correct |
194 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2087 ms |
792 KB |
Time limit exceeded |
2 |
Execution timed out |
2043 ms |
760 KB |
Time limit exceeded |
3 |
Execution timed out |
2089 ms |
888 KB |
Time limit exceeded |
4 |
Correct |
294 ms |
632 KB |
Output is correct |
5 |
Execution timed out |
2089 ms |
1256 KB |
Time limit exceeded |
6 |
Execution timed out |
2081 ms |
1056 KB |
Time limit exceeded |
7 |
Execution timed out |
2089 ms |
1016 KB |
Time limit exceeded |
8 |
Correct |
397 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
2732 KB |
Output is correct |
2 |
Correct |
284 ms |
2664 KB |
Output is correct |
3 |
Correct |
291 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Runtime error |
4 ms |
2688 KB |
Execution killed with signal 11 |
6 |
Runtime error |
3 ms |
2560 KB |
Execution killed with signal 11 |
7 |
Runtime error |
36 ms |
5880 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1204 ms |
752 KB |
Output is correct |
2 |
Correct |
1778 ms |
1016 KB |
Output is correct |
3 |
Execution timed out |
2092 ms |
1756 KB |
Time limit exceeded |
4 |
Execution timed out |
2097 ms |
1760 KB |
Time limit exceeded |
5 |
Execution timed out |
2081 ms |
884 KB |
Time limit exceeded |
6 |
Execution timed out |
2086 ms |
2104 KB |
Time limit exceeded |
7 |
Execution timed out |
2098 ms |
1024 KB |
Time limit exceeded |
8 |
Execution timed out |
2096 ms |
2296 KB |
Time limit exceeded |
9 |
Runtime error |
3 ms |
2432 KB |
Execution killed with signal 11 |
10 |
Execution timed out |
2086 ms |
932 KB |
Time limit exceeded |
11 |
Execution timed out |
2083 ms |
1364 KB |
Time limit exceeded |
12 |
Execution timed out |
2077 ms |
4476 KB |
Time limit exceeded |
13 |
Runtime error |
3 ms |
2560 KB |
Execution killed with signal 11 |