#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
secret.cpp: In function 'int Query(int, int)':
secret.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
67 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
2380 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
125 ms |
2412 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
134 ms |
2388 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
441 ms |
4480 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
454 ms |
4368 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
432 ms |
4276 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
442 ms |
4372 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
438 ms |
4328 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
442 ms |
4380 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
446 ms |
4348 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |