# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885467 | Karoot | Secret (JOI14_secret) | C++17 | 0 ms | 0 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 <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
/*int secret(int a, int b){
secretCounter++;
return max(a, b);
}*/
const int MAXN = 1e3+1;
int SRQ[MAXN][MAXN];
int Ar[MAXN];
int globul;
void initTree(int l, int r){
if (l == r)return;
int mid = (l+r)>>1;
SRQ[mid][mid] = Ar[mid];
SRQ[mid+1][mid+1] = Ar[mid+1];
for (int i = mid-1; i >= l; i--){
SRQ[mid][i] = secret(Ar[i], SRQ[mid][i+1]);
}
for (int i = mid+2; i <= r; i++){
SRQ[mid+1][i] = secret(Ar[i], SRQ[mid+1][i-1]);
}
initTree(l, mid);
initTree(mid+1, r);
}
void Init(int N, int A[]){
for (int i = 0; i < N; i++){
Ar[i] = A[i];
}
globul = N;
initTree(0, N-1);
}
int followInit(int l, int r, int wL, int wR){
int mid = (l+r)>>1;
if (mid >= wL && mid < wR)return secret(SRQ[mid][wL], SRQ[mid+1][wR]);
if (mid == wR){
return SRQ[mid][wL];
}
if (l == r)return -1;
if (mid < wL){
return followInit(mid+1, r, wL, wR);
}
return followInit(l, mid, wL, wR);
}
int Query(int L, int R){
return followInit(0, globul-1, l, r);
}
/*int main(){
scoobydoobydoo();
int N; cin >> N;
int A[8];
for (int i = 0; i < N; i++){
cin >> A[i];
}
int q; cin >> q;
init(N, A);
//cout << "sc " << secretCounter << endl;
while (q--){
int a, b; cin >> a >> b;
cout << query(a, b) << endl;
cout << "sc " << secretCounter << endl;
}
return 0;
}
*/