#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(a[j], val[j - 1][i - 1]);
}
}
}
}
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 |
Incorrect |
115 ms |
2348 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 809782271. |
2 |
Incorrect |
114 ms |
2352 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 68749376. |
3 |
Incorrect |
119 ms |
2432 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 136349820. |
4 |
Incorrect |
532 ms |
4300 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 650789536. |
5 |
Incorrect |
436 ms |
4396 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 377506838. |
6 |
Incorrect |
429 ms |
4456 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 61461050. |
7 |
Incorrect |
441 ms |
4420 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 687550570. |
8 |
Incorrect |
431 ms |
4288 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 145923264. |
9 |
Incorrect |
431 ms |
4308 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 18757135. |
10 |
Incorrect |
445 ms |
4300 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 70590726. |