# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085598 | MrPavlito | Secret (JOI14_secret) | C++17 | 324 ms | 9300 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 <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
//#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e3+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
int niz[MAXN];
int n;
map<pii, int> mapa;
vector<vector<int>> v(MAXN, vector<int>(MAXN));
int ask(int a, int b)
{
if(mapa.count(mp(a,b)))return mapa[mp(a,b)];
int p = Secret(a,b);
mapa[{a,b}] = p;
return p;
}
void build(int l, int r, int lvl)
{
if(l == r)return;
int mid = l+r >> 1;
v[mid][mid] = niz[mid];
v[mid+1][mid+1] = niz[mid+1];
for(int i=mid+2;i<=r; i++)v[mid+1][i] = ask(v[mid+1][i-1], niz[i]);
for(int i=mid-1;i>=l; i--)v[mid][i] = ask( niz[i],v[mid][i+1]);
//for(int i=mid;i>=l; i--)cout << v[lvl][i] << " ";cout << endl;
build(l, mid, lvl+1);
build(mid+1,r, lvl+1);
}
int query(int l, int r, int lvl, int L, int R)
{
int mid = l+r>>1;
if(L <= mid && R> mid)return ask(v[mid][L], v[mid+1][R]);
else if(R == mid)return v[mid][L];
else if(L > mid)return query(mid+1, r, lvl+1, L, R);
else return query(l, mid+1, lvl+1, L, R);
}
void Init(int N, int A[]) {
n = N;
for(int i=1; i<=n; i++)niz[i] = A[i-1];
build(1,n, 0);
}
int Query(int L, int R) {
if(L == R)return niz[L+1];
return (query(1, n, 0, L+1, R+1));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |