# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
605903 | kawaii | Secret (JOI14_secret) | C++14 | 468 ms | 9320 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>
using namespace std;
int a[1005], pre[1005][1005];
map<pair<int, int>, int> mp;
void Init(int N, int A[]){
for(int i = 1; i <= N; i++) a[i] = A[i - 1];
for(int i = 1; i <= N; i++) pre[i][i] = a[i];
for(int i = 1; i <= 9; i++){
for(int j = 1; j + (1 << i) - 1 <= N; j++){
int val = Secret(pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]);
pre[j][j + (1 << i) - 1] = val;
mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
}
}
}
int Query(int L, int R){
int ans = -1; L++; R++;
int diff = R - L + 1;
// cout << diff <<" ";
for(int i = 0; i <= 9; i++){
if((1 << i) & diff){
if(ans == -1) ans = pre[L][L + (1 << i) - 1];
else{
if(mp[{ans, pre[L][L + (1 << i) - 1]}] == 0){
int val = Secret(ans, pre[L][L + (1 << i) - 1]);
mp[{ans, pre[L][L + (1 << i) - 1]}] = mp[{pre[L][L + (1 << i) - 1], ans}] = val;
ans = val;
}
}
L += (1 << i);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |