Submission #957992

#TimeUsernameProblemLanguageResultExecution timeMemory
957992wkspSecret (JOI14_secret)C++14
0 / 100
403 ms4944 KiB
#include<bits/stdc++.h> #include "secret.h" using namespace std; // int Secret(int X, int Y){ // int a; // cin >> a; // return a; // } const int n_max = 1024; const int logn = 12; int tab[logn][n_max]; // int tabr[log][n_max]; map<pair<int, int>, int> result_in_past; int check(int a, int b){ if(result_in_past.find({a, b}) != result_in_past.end()){ return result_in_past[{a, b}]; }else{ int x = Secret(a, b); result_in_past[{a, b}] = x; return x; } } void init_tree(int n, int lvl = 10, int l = 0, int r = n_max - 1){ if(l > n){ return; } if(lvl == 0){ return; } int mid = (l+r)/2; init_tree(n, lvl - 1, l, mid); init_tree(n, lvl - 1, mid + 1, r); if(mid >= n){ return; } tab[lvl][mid] = tab[0][mid]; for(int i = mid - 1; i >= l; i--){ tab[lvl][i] = check(tab[0][i], tab[lvl][i+1]); } tab[lvl][mid + 1] = tab[0][mid+1]; for(int i = mid + 2; i <= min(n, r); i++){ tab[lvl][i] = check(tab[lvl][i-1], tab[0][i]); } } int find_in_tree(int a, int b, int lvl = 10, int l = 0, int r = n_max - 1){ int mid = (l+r)/2; if(b <= mid){ return find_in_tree(a, b, lvl - 1, l, mid); } if(a > mid){ return find_in_tree(a, b, lvl - 1, mid + 1, r); } //return lvl; return check(tab[lvl][l], tab[lvl][r]); } void Init(int N, int A[]){ for(int i = 0; i < N; i++){ tab[0][i] = A[i]; } init_tree(N); } int Query(int L, int R){ if(L == R){ return tab[0][L]; } return find_in_tree(L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...