#include <bits/stdc++.h>
#include "secret.h"
#define endl '\n'
using namespace std;
const int maxn = 1024;
int pref[maxn][maxn], suff[maxn][maxn];
int lf[maxn], rg[maxn], a[maxn];
vector<int> mids;
void divide(int l, int r){
if(l > r)
return;
if(l == r){
suff[l][l] = a[l];
lf[l] = l;
rg[l] = l;
mids.push_back(l);
return;
}
int mid = (l + r) / 2;
mids.push_back(mid);
divide(l, mid - 1);
divide(mid + 1, r);
lf[mid] = l, rg[mid] = r;
suff[mid][l] = a[mid];
pref[mid][mid + 1] = a[mid + 1];
for(int i = mid - 1;i >= l;i--)
suff[mid][i] = Secret(a[i], suff[mid][i + 1]);
for(int i = mid + 2;i <= r;i++)
pref[mid][i] = Secret(pref[mid][i - 1], a[i]);
}
void Init(int n, int A[]){
for(int i = 0;i < n;i++)
a[i] = A[i];
divide(0, n - 1);
}
int Query(int l, int r){
for(int x : mids){
if(lf[x] <= l && rg[x] >= r && x >= l && x <= r){
int ans = suff[x][l];
if(x != r)
ans = Secret(ans, pref[x][r]);
return ans;
}
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
50 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
101 ms |
10856 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 1381272. |
2 |
Incorrect |
99 ms |
10836 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 132821256. |
3 |
Incorrect |
101 ms |
10840 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 614791446. |
4 |
Incorrect |
353 ms |
11604 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 810189514. |
5 |
Incorrect |
361 ms |
11608 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 653807882. |
6 |
Incorrect |
368 ms |
11612 KB |
Wrong Answer: Query(915, 915) - expected : 282904741, actual : 0. |
7 |
Incorrect |
361 ms |
11608 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 620345354. |
8 |
Incorrect |
357 ms |
11600 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 482792768. |
9 |
Incorrect |
363 ms |
11608 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 425200366. |
10 |
Incorrect |
368 ms |
11604 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 72261763. |