#include "secret.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define NIL 1145141919
#define MAX_N (1<<10)
typedef pair<int, int> P;
int seg[MAX_N*2-1];
map<P, int> mp;
int ask(int x, int y) {
if (mp.find(P(x, y)) != mp.end()) return mp[P(x, y)];
return mp[P(x, y)] = Secret(x, y);
}
int op(int x, int y) {
if (x == NIL) return y;
if (y == NIL) return x;
return ask(x, y);
}
int query(int a, int b, int k=0, int l=0, int r=MAX_N) {
if (b <= l || r <= a) return NIL;
if (a <= l && r <= b) return seg[k];
return op(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
}
int N;
void Init(int NN, int A[]) {
N = NN;
fill(seg, seg+MAX_N*2-1, NIL);
rep(i, N) seg[i+MAX_N-1] = A[i];
for (int i=MAX_N-2; i>=0; i--) {
seg[i] = op(seg[i*2+1], seg[i*2+2]);
}
rep(i, N) {
rep(j, 20) {
int p = (1<<j)-1;
if (p >= N) break;
if (p >= i) query(i, p);
}
}
}
int Query(int L, int R) {
int b = L;
rep(j, 20) {
int p = (1<<j)-1;
if (p >= N) break;
if (p >= L) b = p;
}
return op(query(L, b), query(b+1, R));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
159 ms |
6156 KB |
Wrong Answer: Query(113, 206) - expected : 536899947, actual : 809833947. |
2 |
Incorrect |
162 ms |
6156 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 173027520. |
3 |
Incorrect |
160 ms |
6156 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 3393656. |
4 |
Incorrect |
600 ms |
6288 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 322486926. |
5 |
Incorrect |
598 ms |
6288 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 248158272. |
6 |
Incorrect |
616 ms |
6288 KB |
Wrong Answer: Query(915, 915) - expected : 282904741, actual : 1145141919. |
7 |
Incorrect |
582 ms |
6288 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 76787816. |
8 |
Incorrect |
615 ms |
6288 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 411381760. |
9 |
Incorrect |
606 ms |
6288 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 689702665. |
10 |
Incorrect |
589 ms |
6288 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 72616452. |