/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include "secret.h"
#define taskname "bai3"
#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;
const int mxN = 1e3 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[mxN], pref[4 * mxN][mxN];
void build(int l, int r, int idx, int dir) {
if(l == r) {
pref[idx][1] = a[l];
return;
}
if(l == r - 1) {
if(dir) pref[idx][1] = a[l];
else pref[idx][1] = a[r];
pref[idx][2] = a[l] + a[r];
return;
}
int mid = (l + r) >> 1;
build(l, mid, idx * 2, 0);
build(mid + 1, r, idx * 2, 1);
if(l == 1 && r == n) return;
if(dir) {
pref[idx][1] = a[l];
for(int i = 2; i <= (r - l + 1); ++i) {
pref[idx][i] = Secret(pref[idx][i - 1], a[l + i - 1]);
}
return;
}
pref[idx][1] = a[r];
for(int i = 2; i <= (r - l + 1); ++i) {
pref[idx][i] = Secret(pref[idx][i - 1], a[r + 1 - i]);
//op_num++;
}
}
void Init(int N, int A[]) {
n = N;
for(int i = 1; i <= n; ++i) a[i] = A[i];
build(1, n, 1, 0);
}
int query(int l, int r, int idx, int u, int v) {
int mid = (l + r) >> 1;
if(u <= mid && mid <= v) {
if(u == mid) return pref[idx * 2 + 1][v - u + 1];
if(v == mid) return pref[idx * 2][v - u + 1];
int tmp1 = pref[idx * 2][mid - u + 1];
int tmp2 = pref[idx * 2 + 1][v - mid + 1];
return Secret(tmp1, tmp2);
}
if(mid > v) return query(l, mid, idx * 2, u, v);
return query(mid + 1, r, idx * 2 + 1, u, v);
}
int Query(int L, int R) {
++L; ++R;
if(L == R) {
return a[L];
}
if(L == R - 1) return Secret(a[L], a[R]);
return query(1, n, 1, L, R);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
116 ms |
2436 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 536870912. |
2 |
Incorrect |
120 ms |
2380 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 458367232. |
3 |
Incorrect |
113 ms |
2508 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 487606366. |
4 |
Incorrect |
439 ms |
4320 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 652296328. |
5 |
Incorrect |
446 ms |
4332 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 536870912. |
6 |
Incorrect |
458 ms |
4372 KB |
Wrong Answer: Query(915, 915) - expected : 282904741, actual : 206870645. |
7 |
Incorrect |
512 ms |
4400 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 544742408. |
8 |
Incorrect |
448 ms |
4392 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 551989520. |
9 |
Incorrect |
436 ms |
4424 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 679614991. |
10 |
Incorrect |
450 ms |
4300 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 879365507. |