#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int S[200000];
LLI pre[200001],pre2[200001];
struct query { int T,L,R,i; };
bool comp(query a,query b) {
return a.T < b.T;
}
query queries[200000];
LLI ans[200000];
int main() {
int i;
int N,Q,T,L,R;
scanf("%d %d",&N,&Q);
for (i = 0; i < N; i++) scanf("%d",&S[i]);
for (i = 0; i < Q; i++) {
scanf("%d %d %d",&T,&L,&R);
queries[i] = (query){T+1,L-1,R-1,i};
}
sort(queries,queries+Q,comp);
int j,c = 1;
int k = 0,f = 0;
for (i = 0; i < Q; i++) {
if ((i > 0) && (queries[i].T != queries[i-1].T)) f = 0;
while (queries[i].T >= 2*c) {
for (j = N-1; j >= c; j--) S[j] = max(S[j],S[j-c]);
for (j = 0; j < N; j++) pre[j+1] = pre[j]+S[j];
c *= 2;
}
int d = queries[i].T-c;
while ((k < Q) && (queries[k].T == queries[i].T)) k++;
if (!f && (k-i > 10)) {
f = 1;
for (j = 0; j < N; j++) pre2[j+1] = pre2[j]+max(S[j],(j >= d) ? S[j-d]:0);
}
if (f) ans[queries[i].i] = pre2[queries[i].R+1]-pre2[queries[i].L];
else {
LLI a = 0;
if (d > queries[i].L) a += pre[min(d,queries[i].R+1)]-pre[queries[i].L];
int e = max(d,queries[i].L);
if (e <= queries[i].R) {
int *p = S+e,*q = S+(e-d);
int t = queries[i].R-e+1;
for (j = 0; j < t; j++) {
a += (*p > *q) ? *p:*q;
p++,q++;
}
//for (j = e; j <= queries[i].R; j++) a += max(S[j],S[j-d]);
}
ans[queries[i].i] = a;
}
}
for (i = 0; i < Q; i++) printf("%lld\n",ans[i]);
return 0;
}
Compilation message
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:23: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:24:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < N; i++) scanf("%d",&S[i]);
~~~~~^~~~~~~~~~~~
ho_t5.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&T,&L,&R);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 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 |
150 ms |
11564 KB |
Output is correct |
3 |
Correct |
153 ms |
17276 KB |
Output is correct |
4 |
Correct |
153 ms |
17400 KB |
Output is correct |
5 |
Correct |
159 ms |
17528 KB |
Output is correct |
6 |
Correct |
155 ms |
17016 KB |
Output is correct |
7 |
Correct |
154 ms |
17528 KB |
Output is correct |
8 |
Correct |
160 ms |
17400 KB |
Output is correct |
9 |
Correct |
152 ms |
17528 KB |
Output is correct |
10 |
Correct |
155 ms |
17400 KB |
Output is correct |
11 |
Correct |
152 ms |
17656 KB |
Output is correct |
12 |
Correct |
153 ms |
17144 KB |
Output is correct |
13 |
Correct |
152 ms |
17272 KB |
Output is correct |
14 |
Correct |
148 ms |
17144 KB |
Output is correct |
15 |
Correct |
150 ms |
17144 KB |
Output is correct |
16 |
Correct |
148 ms |
17144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
173 ms |
9336 KB |
Output is correct |
3 |
Correct |
176 ms |
9080 KB |
Output is correct |
4 |
Correct |
170 ms |
9336 KB |
Output is correct |
5 |
Correct |
168 ms |
9080 KB |
Output is correct |
6 |
Correct |
168 ms |
9080 KB |
Output is correct |
7 |
Correct |
173 ms |
9208 KB |
Output is correct |
8 |
Correct |
166 ms |
9336 KB |
Output is correct |
9 |
Correct |
174 ms |
9212 KB |
Output is correct |
10 |
Correct |
168 ms |
9208 KB |
Output is correct |
11 |
Correct |
166 ms |
9336 KB |
Output is correct |
12 |
Correct |
163 ms |
9080 KB |
Output is correct |
13 |
Correct |
170 ms |
9336 KB |
Output is correct |
14 |
Correct |
167 ms |
9080 KB |
Output is correct |
15 |
Correct |
166 ms |
9336 KB |
Output is correct |
16 |
Correct |
160 ms |
9080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
7300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Execution timed out |
1089 ms |
7160 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |