# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41567 | funcsr | Secret (JOI14_secret) | C++14 | 618 ms | 12628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "secret.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define MAX_N (1<<10)
typedef pair<int, int> P;
int seg[MAX_N*2-1];
map<P, int> mp;
int ask(int x, int y) {
if (mp.find(P(x, y)) != mp.end()) return mp[P(x, y)];
return mp[P(x, y)] = Secret(x, y);
}
int N;
int A[1000];
int Tleft[1000][1000], Tright[1000][1000];
void precalc(int l, int r) {
if (l == r) return;
int mid = (l+r)/2;
Tleft[mid][mid] = A[mid];
for (int x=mid-1; x>=l; x--) Tleft[mid][x] = Secret(A[x], Tleft[mid][x+1]);
Tright[mid][mid+1] = A[mid+1];
for (int x=mid+2; x<=r; x++) Tright[mid][x] = Secret(Tright[mid][x-1], A[x]);
precalc(l, mid);
precalc(mid+1, r);
}
int f(int l, int r, int a, int b) {
if (l == r) return A[l];
int mid = (l+r)/2;
if (a <= mid && mid <= b) {
int x = Tleft[mid][a];
if (mid < b) x = Secret(x, Tright[mid][b]);
return x;
}
if (b < mid) return f(l, mid, a, b);
else return f(mid+1, r, a, b);
}
void Init(int NN, int AA[]) {
N = NN;
rep(i, N) A[i] = AA[i];
precalc(0, N-1);
}
int Query(int L, int R) {
return f(0, N-1, L, R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |