# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
824995 |
2023-08-14T13:00:16 Z |
QwertyPi |
Hacker (BOI15_hac) |
C++14 |
|
32 ms |
13424 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 11;
const int LGN = 21;
int a[MAXN], s[MAXN * 3], b[MAXN * 2];
struct SparseTable{
int st[LGN][MAXN];
void init(int n, int* a, int (*g)(int, int)){
f = g;
for(int i = 0; i < n; i++) st[0][i] = a[i];
for(int j = 1; j < LGN; j++){
for(int i = 0; i <= n - (1 << j); i++){
st[j][i] = f(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
}
}
}
int qry(int l, int r){
int d = __lg(r - l + 1);
return f(st[d][l], st[d][r - (1 << d) + 1]);
}
int (*f)(int, int);
} ST;
int32_t main(){
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) a[i + n * 2] = a[i + n] = a[i];
for(int i = 0; i < n * 3; i++) s[i + 1] = s[i] + a[i];
for(int i = 0; i < n * 2; i++) b[i] = s[i + (n + 1) / 2] - s[i];
ST.init(n * 2, b, [](int a, int b){ return min(a, b); });
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, ST.qry(i, i + (n + 1) / 2 - 1));
}
cout << ans << endl;
}
Compilation message
hac.cpp: In member function 'void SparseTable::init(int, int*, int (*)(int, int))':
hac.cpp:16:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
16 | st[j][i] = f(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
396 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
396 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
436 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
696 KB |
Output is correct |
25 |
Correct |
2 ms |
980 KB |
Output is correct |
26 |
Correct |
2 ms |
980 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
3 ms |
1084 KB |
Output is correct |
4 |
Correct |
27 ms |
13424 KB |
Output is correct |
5 |
Runtime error |
32 ms |
4300 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
396 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
436 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
696 KB |
Output is correct |
25 |
Correct |
2 ms |
980 KB |
Output is correct |
26 |
Correct |
2 ms |
980 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
1088 KB |
Output is correct |
32 |
Correct |
0 ms |
308 KB |
Output is correct |
33 |
Correct |
1 ms |
432 KB |
Output is correct |
34 |
Correct |
3 ms |
1084 KB |
Output is correct |
35 |
Correct |
27 ms |
13424 KB |
Output is correct |
36 |
Runtime error |
32 ms |
4300 KB |
Execution killed with signal 11 |
37 |
Halted |
0 ms |
0 KB |
- |