# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656738 | minhcool | Secret (JOI14_secret) | C++17 | 454 ms | 4480 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<bits/stdc++.h>
#include "secret.h"
//#include "factories.h"
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const ll N = 1e3 + 5, oo = 1e18 + 7, mod = 1e9 + 7;
int n, a[N];
int arr[N][11];
int val[N][11];
vector<ii> segments[11];
/*
int Secret(int x, int y){
return x + 2 * (y/2);
}*/
void Init(int N, int A[]){
n = N;
for(int i = 0; i < n; i++) a[i + 1] = A[i];
segments[0].pb({1, n});
for(int i = 1; i <= 10; i++){
int temp = 0;
for(auto it : segments[i - 1]){
//cout << i - 1 << " " << it.fi << " " << it.se << "\n";
temp++;
for(int j = it.fi; j <= it.se; j++) arr[j][i - 1] = temp;
if(it.fi == it.se) continue;
int mid = (it.fi + it.se) >> 1;
segments[i].pb({it.fi, mid});
segments[i].pb({mid + 1, it.se});
val[mid][i - 1] = a[mid];
val[mid + 1][i - 1] = a[mid + 1];
for(int j = mid - 1; j >= it.fi; j--){
val[j][i - 1] = Secret(a[j], val[j + 1][i - 1]);
}
for(int j = mid + 2; j <= it.se; j++){
val[j][i - 1] = Secret(val[j - 1][i - 1], a[j]);
}
}
}
}
int Query(int l, int r){
l++, r++;
if(l == r) return a[l];
for(int i = 10; i >= 0; i--){
if(!arr[l][i] || !arr[r][i]) continue;
if(arr[l][i] == arr[r][i]){
//out << l << " " << r << " " << i << "\n";
//cout << val[l][i] << " " << val[r][i] << "\n";
return Secret(val[l][i], val[r][i]);
}
}
}
/*
void process(){
int n, q, a[1005];
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
cin >> q;
Init(n, a);
while(q--){
int l, r;
cin >> l >> r;
cout << Query(l, r) << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
process();
}*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |