#include <bits/stdc++.h>
using namespace std;
long long S[200005];
int T[200005];
int L[200005];
int R[200005];
long long ans[200005];
long long val[(1<<20)+5];
long long lazyadd[(1<<20)+5];
int N;
long long prefixSum[1000005];
inline int left1(int x){
return (x<<1)+1;
}
inline int right1(int x){
return (x<<1)+2;
}
void init(int i = 0, int s = 1, int e = N){
int m = (s+e)>>1;
lazyadd[i] = 0;
if(s == e){
val[i] = S[s];
}else{
int l = left1(i);
int r = right1(i);
init(l, s, m);
init(r, m+1, e);
val[i] = max(val[l], val[r]);
}
}
long long rmq(int x, int y, int i = 0, int s = 1, int e = N){
int m = (s+e)>>1;
if(x <= s && e <= y){
return val[i];
}
int l = left1(i);
int r = right1(i);
if(x > m){
return rmq(x, y, r, m+1, e);
}else if(y <= m){
return rmq(x, y, l, s, m);
}else{
return max(rmq(x, y, r, m+1, e), rmq(x, y, l, s, m));
}
}
int main(){
int Q;
scanf("%d%d", &N, &Q);
for(int i = 1; i <= N; i ++){
scanf("%d", &S[i]);
}
for(int i = 0; i < Q; i ++){
scanf("%d%d%d", &T[i], &L[i], &R[i]);
}
init();
prefixSum[0] = 0;
for(int i = 1; i <= N; i ++){
prefixSum[i] = prefixSum[i-1] + rmq(max(i-T[0],1), i);
}
for(int i = 0; i < Q; i ++){
int t = T[i];
int l = L[i];
int r = R[i];
if(t == T[0]){
printf("%lld\n", prefixSum[r]-prefixSum[l-1]);
continue;
}
long long ans = 0;
for(int j = l; j <= r; j ++){
//printf("%d ", rmq(max(j-t, 1), j));
ans += rmq(max(j-t, 1), j);
}
//printf("\n");
printf("%lld\n", ans);
}
}
Compilation message
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:61:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
scanf("%d", &S[i]);
~~~~~^
ho_t5.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &S[i]);
~~~~~^~~~~~~~~~~~~
ho_t5.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &T[i], &L[i], &R[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
168 ms |
22520 KB |
Output is correct |
3 |
Correct |
166 ms |
22520 KB |
Output is correct |
4 |
Correct |
177 ms |
22520 KB |
Output is correct |
5 |
Correct |
175 ms |
22524 KB |
Output is correct |
6 |
Correct |
186 ms |
22264 KB |
Output is correct |
7 |
Correct |
182 ms |
22648 KB |
Output is correct |
8 |
Correct |
183 ms |
22644 KB |
Output is correct |
9 |
Correct |
177 ms |
22648 KB |
Output is correct |
10 |
Correct |
189 ms |
22520 KB |
Output is correct |
11 |
Correct |
186 ms |
22776 KB |
Output is correct |
12 |
Correct |
168 ms |
22392 KB |
Output is correct |
13 |
Correct |
195 ms |
22392 KB |
Output is correct |
14 |
Correct |
176 ms |
22240 KB |
Output is correct |
15 |
Correct |
176 ms |
22392 KB |
Output is correct |
16 |
Correct |
185 ms |
22520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
235 ms |
18808 KB |
Output is correct |
3 |
Correct |
224 ms |
18808 KB |
Output is correct |
4 |
Correct |
216 ms |
18936 KB |
Output is correct |
5 |
Correct |
229 ms |
18808 KB |
Output is correct |
6 |
Correct |
216 ms |
18808 KB |
Output is correct |
7 |
Correct |
211 ms |
18808 KB |
Output is correct |
8 |
Correct |
232 ms |
18936 KB |
Output is correct |
9 |
Correct |
215 ms |
18864 KB |
Output is correct |
10 |
Correct |
222 ms |
18680 KB |
Output is correct |
11 |
Correct |
231 ms |
18936 KB |
Output is correct |
12 |
Correct |
227 ms |
18808 KB |
Output is correct |
13 |
Correct |
221 ms |
18992 KB |
Output is correct |
14 |
Correct |
224 ms |
18808 KB |
Output is correct |
15 |
Correct |
223 ms |
19064 KB |
Output is correct |
16 |
Correct |
219 ms |
18680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
17912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Execution timed out |
1091 ms |
19448 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |