#include "secret.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
//#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e3+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
int niz[MAXN];
int n;
map<pii, int> mapa;
vector<vector<int>> v(MAXN, vector<int>(MAXN));
int ask(int a, int b)
{
if(mapa.count(mp(a,b)))return mapa[mp(a,b)];
int p = Secret(a,b);
mapa[{a,b}] = p;
return p;
}
void build(int l, int r, int lvl)
{
if(l == r)return;
int mid = l+r >> 1;
v[mid][mid] = niz[mid];
v[mid+1][mid+1] = niz[mid+1];
for(int i=mid+2;i<=r; i++)v[mid+1][i] = ask(v[mid+1][i-1], niz[i]);
for(int i=mid-1;i>=l; i--)v[mid][i] = ask( niz[i],v[mid][i+1]);
//for(int i=mid;i>=l; i--)cout << v[lvl][i] << " ";cout << endl;
build(l, mid, lvl+1);
build(mid+1,r, lvl+1);
}
void Init(int N, int A[]) {
n = N;
for(int i=1; i<=n; i++)niz[i] = A[i-1];
build(1,n, 0);
}
int Query(int L, int R) {
if(L == R)return niz[L+1];
int l = 1;int r = n;
while(l<r)
{
int mid = l+r>>1;
if(L <= mid && R> mid)return ask(v[mid][L], v[mid+1][R]);
else if(R == mid)return v[mid][L];
else if(L > mid)l = mid+1;
else r = mid;
}
return v[l][l];
}
Compilation message
secret.cpp: In function 'void build(int, int, int)':
secret.cpp:32:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l+r >> 1;
| ~^~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:55:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
6736 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 22166791. |
2 |
Incorrect |
84 ms |
6728 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 306225408. |
3 |
Incorrect |
85 ms |
6716 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 629483540. |
4 |
Incorrect |
310 ms |
8788 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 34079308. |
5 |
Incorrect |
334 ms |
8768 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 542818560. |
6 |
Incorrect |
317 ms |
8780 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 60946066. |
7 |
Incorrect |
331 ms |
8764 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 772352096. |
8 |
Incorrect |
333 ms |
8788 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 290455552. |
9 |
Incorrect |
345 ms |
8668 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 164632041. |
10 |
Incorrect |
322 ms |
8788 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 872638089. |