#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
/*
int Secret(int x, int y) {
return min(x + 2 * (y / 2), (int)1e9);
}
*/
const int N = 1001;
vector<int> a(N);
int x[N][N];
void Init(int n, int A[]) {
for(int i = 0; i < n; i++) {
a[i] = A[i];
}
for(int i = 0; i < n; i++) {
x[i][0] = a[i];
}
for (int j = 1; (1 << j) <= n; j++) {
for (int i = 0; i + (1 << j) - 1 < n; i++) {
x[i][j] = Secret(x[i][j - 1] , x[i + (1 << (j - 1))][j - 1]);
//cout << i << " " << i + (1LL << j) - 1 << " " << x[i][j] << "\n";
}
}
}
int Query(int l, int r) {
vector<int> V;
int ans = - 1;
while(l <= r) {
int p = - 1;
for(int i = 10; i >= 0; i--) {
if(l + (1LL << i) - 1 <= r) {
// takes this one
p = l + (1LL << i);
if(ans == - 1) {
ans = x[l][i];
}
else {
ans = Secret(ans, x[l][i]);
}
break;
}
}
l = p;
}
return ans;
}
/*
int main() {
int Q[4] = {1, 4, 7, 2};
Init(4, Q);
cout << Query(0, 3);
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |