# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
101152 |
2019-03-17T06:37:22 Z |
E869120 |
Cake (CEOI14_cake) |
C++14 |
|
2000 ms |
7000 KB |
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)
class RangeMax {
public:
vector<int>dat; int size_ = 1;
void init(int sz) {
while (size_ <= sz) size_ *= 2;
dat.resize(size_ * 2, 0);
}
void update(int pos, int x) {
pos += size_; dat[pos] = x;
while (pos >= 2) {
pos /= 2;
dat[pos] = max(dat[pos * 2], dat[pos * 2 + 1]);
}
}
int query_(int l, int r, int a, int b, int u) {
if (l <= a && b <= r) return dat[u];
if (r <= a || b <= l) return -(1 << 30);
int v1 = query_(l, r, a, (a + b) >> 1, u * 2);
int v2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
return max(v1, v2);
}
int query(int l, int r) {
return query_(l, r, 0, size_, 1);
}
};
int N, Q, A, P[1 << 19], C[1 << 19], q[1 << 19], D[1 << 19]; bool used[1 << 19];
int cnt1;
char op[1 << 19]; int x[1 << 19], e[1 << 19];
pair<int, int> Top10[11];
int power[1 << 19];
vector<int> solve_Jury() {
vector<int>L;
for (int i = N; i >= 1; i--) {
for (int j = 1; j <= N; j++) { if (P[j] == i) L.push_back(j); }
}
vector<int>FinalAns;
for (int i = 1; i <= Q; i++) {
if (op[i] == 'E') {
vector<int>L2;
for (int j = 0; j < e[i] - 1; j++) L2.push_back(L[j]);
L2.push_back(x[i]);
for (int j = e[i]; j < L.size(); j++) { if (L[j] != x[i]) L2.push_back(L[j]); }
L = L2;
}
if (op[i] == 'F') {
if (x[i] == A) {
FinalAns.push_back(0);
}
else {
for (int i = 0; i < L.size(); i++) power[L[i]] = i;
int cl = A - 1, cr = A + 1, sum = 0;
while (true) {
int Z1 = -1; if (cl >= 1) Z1 = power[cl];
int Z2 = -1; if (cr <= N) Z2 = power[cr];
if (Z1 > Z2) { if (cl == x[i]) break; cl--; }
if (Z1 < Z2) { if (cr == x[i]) break; cr++; }
sum++;
}
FinalAns.push_back(sum + 1);
}
}
}
return FinalAns;
}
vector<int> solve_Output() {
for (int i = 0; i <= 9; i++) {
for (int j = 1; j <= N; j++) { if (N - i == P[j]) Top10[i] = make_pair(N - i, j); }
}
sort(Top10, Top10 + 11, greater<pair<int, int>>());
// Top10 と番号を管理
for (int i = 1; i <= Q; i++) {
if (op[i] == 'E') {
// 変更部分
int Z = Top10[0].first + 1; if (e[i] >= 2) Z = Top10[e[i] - 2].first;
for (int j = 0; j < e[i] - 1; j++) { P[Top10[j].second]++; Top10[j].first += 1; }
int flag = 10; Top10[10] = make_pair(-1, -1);
for (int j = 0; j < 10; j++) { if (Top10[j].second == x[i]) flag = j; }
Top10[flag] = make_pair(Z, x[i]);
sort(Top10, Top10 + 11, greater<pair<int, int>>());
if (q[x[i]] == 0) { D[x[i]] = P[x[i]]; }
else { e[q[x[i]]] = P[x[i]]; }
P[x[i]] = Z; q[x[i]] = i;
}
}
for (int i = 1; i <= N; i++) {
if (q[i] == 0) D[i] = P[i];
else e[q[i]] = P[i];
}
vector<int>FinalAns;
// 本質: RMQ におけるクエリ
RangeMax X; X.init(N + 2);
for (int i = 1; i <= N; i++) X.update(i, D[i]);
for (int i = 1; i <= Q; i++) {
if (op[i] == 'E') {
X.update(x[i], e[i]);
}
if (op[i] == 'F') {
if (x[i] == A) {
FinalAns.push_back(0);
}
if (x[i] < A) {
int score = (A - x[i]), G = X.query(x[i], A);
int L = A + 1, R = N + 1, M, maxn = -(1 << 30);
for (int j = 0; j < 22; j++) {
M = (L + R) / 2;
int F = X.query(A + 1, M + 1);
if (F < G) { maxn = max(maxn, M); L = M; }
else { R = M; }
}
if (maxn != -(1 << 30)) score += (maxn - A);
FinalAns.push_back(score);
}
if (x[i] > A) {
int score = (x[i] - A), G = X.query(A + 1, x[i] + 1);
int L = 1, R = A, M, minx = (1 << 30);
for (int j = 0; j < 22; j++) {
M = (L + R) / 2;
int F = X.query(M, A);
if (F < G) { minx = min(minx, M); R = M; }
else { L = M; }
}
if (minx != (1 << 30)) score += (A - minx);
FinalAns.push_back(score);
}
}
}
return FinalAns;
}
int main() {
// 入力
scanf("%d%d", &N, &A);
for (int i = 1; i <= N; i++) scanf("%d", &P[i]);
scanf("%d", &Q);
for (int i = 1; i <= Q; i++) { cin >> op[i]; if (op[i] == 'E') scanf("%d%d", &x[i], &e[i]); if (op[i] == 'F') scanf("%d", &x[i]); }
vector<int>T = solve_Jury();
for (int i = 0; i < T.size(); i++) printf("%d\n", T[i]);
return 0;
}
Compilation message
cake.cpp:7:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable: 4996)
cake.cpp: In function 'std::vector<int> solve_Jury()':
cake.cpp:55:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = e[i]; j < L.size(); j++) { if (L[j] != x[i]) L2.push_back(L[j]); }
~~^~~~~~~~~~
cake.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); i++) power[L[i]] = i;
~~^~~~~~~~~~
cake.cpp: In function 'int main()':
cake.cpp:160:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < T.size(); i++) printf("%d\n", T[i]);
~~^~~~~~~~~~
cake.cpp:154:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &A);
~~~~~^~~~~~~~~~~~~~~~
cake.cpp:155:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= N; i++) scanf("%d", &P[i]);
~~~~~^~~~~~~~~~~~~
cake.cpp:156:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q);
~~~~~^~~~~~~~~~
cake.cpp:157:70: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= Q; i++) { cin >> op[i]; if (op[i] == 'E') scanf("%d%d", &x[i], &e[i]); if (op[i] == 'F') scanf("%d", &x[i]); }
~~~~~^~~~~~~~~~~~~~~~~~~~~~
cake.cpp:157:117: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= Q; i++) { cin >> op[i]; if (op[i] == 'E') scanf("%d%d", &x[i], &e[i]); if (op[i] == 'F') scanf("%d", &x[i]); }
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2044 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2051 ms |
4980 KB |
Time limit exceeded |
2 |
Execution timed out |
2025 ms |
5112 KB |
Time limit exceeded |
3 |
Execution timed out |
2051 ms |
5060 KB |
Time limit exceeded |
4 |
Execution timed out |
2035 ms |
5032 KB |
Time limit exceeded |
5 |
Execution timed out |
2045 ms |
5616 KB |
Time limit exceeded |
6 |
Execution timed out |
2047 ms |
5536 KB |
Time limit exceeded |
7 |
Execution timed out |
2035 ms |
7000 KB |
Time limit exceeded |
8 |
Execution timed out |
2017 ms |
5424 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2009 ms |
1916 KB |
Time limit exceeded |
2 |
Execution timed out |
2050 ms |
1764 KB |
Time limit exceeded |
3 |
Execution timed out |
2040 ms |
1784 KB |
Time limit exceeded |
4 |
Execution timed out |
2035 ms |
384 KB |
Time limit exceeded |
5 |
Execution timed out |
2052 ms |
2164 KB |
Time limit exceeded |
6 |
Execution timed out |
2045 ms |
2256 KB |
Time limit exceeded |
7 |
Execution timed out |
2050 ms |
2240 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2047 ms |
884 KB |
Time limit exceeded |
2 |
Execution timed out |
2020 ms |
1044 KB |
Time limit exceeded |
3 |
Execution timed out |
2061 ms |
1680 KB |
Time limit exceeded |
4 |
Execution timed out |
2040 ms |
1636 KB |
Time limit exceeded |
5 |
Execution timed out |
2055 ms |
1656 KB |
Time limit exceeded |
6 |
Execution timed out |
2072 ms |
2040 KB |
Time limit exceeded |
7 |
Execution timed out |
2067 ms |
2344 KB |
Time limit exceeded |
8 |
Execution timed out |
2057 ms |
2808 KB |
Time limit exceeded |
9 |
Execution timed out |
2062 ms |
5940 KB |
Time limit exceeded |
10 |
Execution timed out |
2054 ms |
4728 KB |
Time limit exceeded |
11 |
Execution timed out |
2049 ms |
5420 KB |
Time limit exceeded |
12 |
Execution timed out |
2062 ms |
5720 KB |
Time limit exceeded |
13 |
Execution timed out |
2059 ms |
5832 KB |
Time limit exceeded |