#include "secret.h"
#include <vector>
using namespace std;
template<class T> struct onlineDQ {
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) { if(a == -1) return b; if(b == -1) return b; return Secret(a, b); } // associative operation
void fill(int l, int r, int ind) {
if(ind == 0) {
stor[l][ind] = a[l];
return;
}
int m = (l+r)/2;
stor[m][ind] = a[m];
for(int i = m - 1; i >= l; i--) stor[i][ind] = comb(a[i], stor[i + 1][ind]);
stor[m + 1][ind] = a[m + 1];
for(int i = m + 2; i < r; i++) stor[i][ind] = comb(stor[i - 1][ind] ,a[i]);
fill(l,m,ind-1); fill(m,r,ind-1);
}
void init() {
n = 1; while ((1<<n) < (int)a.size()) ++n;
while(a.size() < (1 << n)) a.push_back(-1);
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]);
}
};
onlineDQ<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);
}
Compilation message
secret.cpp: In instantiation of 'void onlineDQ<T>::init() [with T = int]':
secret.cpp:40:12: required from here
secret.cpp:25:20: warning: comparison of integer expressions of different signedness: 'std::vector<int, std::allocator<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | while(a.size() < (1 << n)) a.push_back(-1);
| ~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
118 ms |
2356 KB |
Wrong Answer: Query(493, 496) - expected : 990344084, actual : 692145173. |
2 |
Incorrect |
116 ms |
2316 KB |
Wrong Answer: Query(236, 238) - expected : 173116186, actual : 800141843. |
3 |
Incorrect |
116 ms |
2360 KB |
Wrong Answer: Query(130, 131) - expected : 127065177, actual : 411394072. |
4 |
Incorrect |
481 ms |
4268 KB |
Wrong Answer: Query(216, 220) - expected : 518824820, actual : 467952034. |
5 |
Incorrect |
458 ms |
4216 KB |
Wrong Answer: Query(584, 592) - expected : 111053842, actual : 895372370. |
6 |
Incorrect |
462 ms |
4244 KB |
Wrong Answer: Query(200, 208) - expected : 277813445, actual : 966582165. |
7 |
Correct |
463 ms |
4232 KB |
Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
460 ms |
4252 KB |
Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
529 ms |
4312 KB |
Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
430 ms |
4408 KB |
Output is correct - number of calls to Secret by Init = 7986, maximum number of calls to Secret by Query = 1 |