#include "secret.h"
#include <vector>
using namespace std;
template<class T> struct offlineDQ {
static const int SZ = (1 << 10);
int n;
T stor[SZ][32-__builtin_clz(SZ)], id = 1;
vector<T> a;
T comb (T a, T b) { return Secret(a, b); } // associative operation
void fill(int l, int r, int ind) {
if (ind < 0) return;
int m = (l+r)/2;
T prod = a[m - 1];
if(l <= m - 1) stor[m - 1][ind] = prod;
for(int i = m - 2; i >= l; i--) stor[i][ind] = prod = comb(a[i],prod);
prod = a[m];
if(m < r) stor[m][ind] = prod;
for(int i = m + 1; i < r; i++) stor[i][ind] = prod = comb(prod,a[i]);
fill(l,m,ind-1); fill(m,r,ind-1);
}
void init() {
n = 1; while ((1<<n) < (int)a.size()) ++n;
a.resize(1<<n);
fill(0,(1<<n),n-1);
}
T query(int l, int r) {
if (l == r) return a[l];
int t = 31-__builtin_clz(r^l);
return comb(stor[l][t],stor[r][t]);
}
};
offlineDQ<int> odq;
void Init(int N, int A[]) {
odq.a.resize(N);
for(int i = 0; i < N; i++) odq.a[i] = A[i];
odq.init();
}
int Query(int L, int R) {
return odq.query(--L, --R);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
2316 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 22166791. |
2 |
Incorrect |
115 ms |
2332 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 306225408. |
3 |
Incorrect |
110 ms |
2360 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 629483540. |
4 |
Incorrect |
436 ms |
4236 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 34079308. |
5 |
Incorrect |
419 ms |
4284 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 542818560. |
6 |
Incorrect |
424 ms |
4288 KB |
Wrong Answer: Query(915, 915) - expected : 282904741, actual : 579799611. |
7 |
Incorrect |
420 ms |
4300 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 772352096. |
8 |
Incorrect |
422 ms |
4300 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 290455552. |
9 |
Incorrect |
427 ms |
4276 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 164632041. |
10 |
Incorrect |
419 ms |
4368 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 872638089. |