/**
* author: milos
* created: 26.12.2020 00:20:30
**/
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
/*#define MAX_VALUE 1000000000
int Secret(int X, int Y) {
return (X + 2 * (Y / 2) < MAX_VALUE) ? (X + 2 * (Y / 2)) : MAX_VALUE;
}*/
vector<pair<int, pair<vector<int>, vector<int>>>> ans;
int Query(int l, int r) {
for (auto c : ans) {
if (c.first >= l && c.first <= r) {
if (r == c.first) {
int j = c.first - l;
return c.second.first[j];
}
int j = c.first - l, z = r - c.first - 1;
return Secret(c.second.first[j], c.second.second[z]);
}
}
return 0;
}
void Solve(int l, int r) {
if (l > r) {
return;
}
int mid = (l + r) / 2;
vector<int> pref, suf;
int x = a[mid];
pref.push_back(x);
for (int i = mid - 1; i >= l; i--) {
x = Secret(a[i], x);
pref.push_back(x);
}
if (mid + 1 < (int) a.size()) {
x = a[mid + 1];
suf.push_back(x);
for (int i = mid + 2; i <= r; i++) {
x = Secret(x, a[i]);
suf.push_back(x);
}
}
ans.push_back({mid, {pref, suf}});
Solve(l, mid - 1);
Solve(mid + 1, r);
}
void Init(int N, int* A) {
for (int i = 0; i < N; i++) {
a.push_back(A[i]);
}
Solve(0, N - 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
2540 KB |
Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
189 ms |
2540 KB |
Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
188 ms |
2540 KB |
Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
591 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
589 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
764 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
509 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
518 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
508 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
514 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |