//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include "secret.h"
#define ll long long
const int nmax = 1000 + 5;
using namespace std;
int n, a[nmax];
int L[nmax << 2][nmax], R[nmax << 2][nmax];
//int Secret(int a, int b){
//}
void build(int id, int l, int r){
if(l == r) return;
int mid = r + l >> 1;
L[id][mid] = a[mid];
R[id][mid + 1] = a[mid + 1];
for(int i = mid - 1; i >= l; --i) L[id][i] = Secret(a[i],L[id][i + 1]);
for(int i = mid + 2; i <= r; ++i) R[id][i] = Secret(R[id][i - 1], a[i]);
build(id << 1, l, mid);
build(id << 1| 1, mid + 1, r);
}
int get(int id, int l, int r, int u, int v){
int mid = r + l >> 1;
if(u <= mid && mid + 1 <= v) return Secret(L[id][u], R[id][v]);
if(u == mid + 1) return R[id][v];
if(v== mid) return L[id][u];
if(mid < u) return get(id << 1 | 1, mid + 1, r, u, v);
if(mid + 1 > v) return get(id << 1, l, mid, u, v);
return get(id << 1, l, mid, u, v)+ get(id << 1 | 1, mid + 1, r, u, v);
}
void Init(int N, int A[]){
n = N;
for(int i = 0; i < n; ++i) a[i] = A[i];
build(1, 0, n - 1);
}
int Query(int l, int r){
if(l == r) return a[l];
return get(1, 0, n - 1, l, r);
}
Compilation message
secret.cpp: In function 'void build(int, int, int)':
secret.cpp:18:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
18 | int mid = r + l >> 1;
| ~~^~~
secret.cpp: In function 'int get(int, int, int, int, int)':
secret.cpp:27:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int mid = r + l >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
10840 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
87 ms |
11088 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
71 ms |
10832 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
264 ms |
14936 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
264 ms |
14936 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
258 ms |
14932 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
261 ms |
14928 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
257 ms |
14932 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
262 ms |
14936 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
264 ms |
14932 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |