#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
const int N_ = 150005;
const int B = 110;
int N, Q, X[N_], S[N_], SN, P[N_];
vector<int> W[N_];
ll precalc[N_/B][N_/B], C[N_];
int main() {
scanf("%d%d", &N, &Q);
for(int i = 0; i < N; i++) {
scanf("%d", X+i);
S[i] = X[i];
}
sort(S, S+N);
SN = unique(S, S+N) - S;
for(int i = 0; i < N; i++) {
P[i] = lower_bound(S, S+SN, X[i]) - S;
W[P[i]].push_back(i);
}
for(int i = 0; i < N; i += B) {
for(int j = 0; j < N; j++) C[j] = 0;
ll val = 0;
for(int j = i; j < N; j++) {
C[P[j]] += (ll)X[j];
if(val < C[P[j]]) val = C[P[j]];
if(j % B == 0) precalc[i/B][j/B] = val;
}
}
while(Q--) {
int a, b; scanf("%d%d", &a, &b); --a; --b;
int x = a, y = b;
ll ans = 0;
for(; x % B != 0; ++x) {
ll val = (ll)X[x] * (lower_bound(W[P[x]].begin(), W[P[x]].end(), b+1) - lower_bound(W[P[x]].begin(), W[P[x]].end(), a));
if(val > ans) ans = val;
}
for(; y % B != 0; --y) {
ll val = (ll)X[y] * (lower_bound(W[P[y]].begin(), W[P[y]].end(), b+1) - lower_bound(W[P[y]].begin(), W[P[y]].end(), a));
if(val > ans) ans = val;
}
ans = max(ans, precalc[x/B][y/B]);
printf("%lld\n", ans);
}
return 0;
}
Compilation message
historic.cpp: In function 'int main()':
historic.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d%d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~
historic.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", X+i);
| ~~~~~^~~~~~~~~~~
historic.cpp:63:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | int a, b; scanf("%d%d", &a, &b); --a; --b;
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3920 KB |
Output is correct |
2 |
Correct |
3 ms |
3920 KB |
Output is correct |
3 |
Correct |
4 ms |
3924 KB |
Output is correct |
4 |
Correct |
4 ms |
3920 KB |
Output is correct |
5 |
Correct |
3 ms |
3920 KB |
Output is correct |
6 |
Correct |
4 ms |
3920 KB |
Output is correct |
7 |
Correct |
4 ms |
3920 KB |
Output is correct |
8 |
Correct |
4 ms |
4088 KB |
Output is correct |
9 |
Correct |
4 ms |
3920 KB |
Output is correct |
10 |
Correct |
3 ms |
3920 KB |
Output is correct |
11 |
Correct |
3 ms |
3920 KB |
Output is correct |
12 |
Correct |
3 ms |
3920 KB |
Output is correct |
13 |
Correct |
3 ms |
3920 KB |
Output is correct |
14 |
Correct |
4 ms |
3968 KB |
Output is correct |
15 |
Correct |
5 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3920 KB |
Output is correct |
2 |
Correct |
3 ms |
3920 KB |
Output is correct |
3 |
Correct |
4 ms |
3924 KB |
Output is correct |
4 |
Correct |
4 ms |
3920 KB |
Output is correct |
5 |
Correct |
3 ms |
3920 KB |
Output is correct |
6 |
Correct |
4 ms |
3920 KB |
Output is correct |
7 |
Correct |
4 ms |
3920 KB |
Output is correct |
8 |
Correct |
4 ms |
4088 KB |
Output is correct |
9 |
Correct |
4 ms |
3920 KB |
Output is correct |
10 |
Correct |
3 ms |
3920 KB |
Output is correct |
11 |
Correct |
3 ms |
3920 KB |
Output is correct |
12 |
Correct |
3 ms |
3920 KB |
Output is correct |
13 |
Correct |
3 ms |
3920 KB |
Output is correct |
14 |
Correct |
4 ms |
3968 KB |
Output is correct |
15 |
Correct |
5 ms |
4176 KB |
Output is correct |
16 |
Correct |
4 ms |
3920 KB |
Output is correct |
17 |
Correct |
5 ms |
3920 KB |
Output is correct |
18 |
Correct |
6 ms |
4028 KB |
Output is correct |
19 |
Correct |
13 ms |
3920 KB |
Output is correct |
20 |
Correct |
21 ms |
4176 KB |
Output is correct |
21 |
Correct |
36 ms |
4176 KB |
Output is correct |
22 |
Correct |
32 ms |
4176 KB |
Output is correct |
23 |
Correct |
38 ms |
4176 KB |
Output is correct |
24 |
Correct |
41 ms |
4444 KB |
Output is correct |
25 |
Correct |
23 ms |
4176 KB |
Output is correct |
26 |
Correct |
25 ms |
4308 KB |
Output is correct |
27 |
Correct |
22 ms |
4176 KB |
Output is correct |
28 |
Correct |
22 ms |
4176 KB |
Output is correct |
29 |
Correct |
25 ms |
4176 KB |
Output is correct |
30 |
Correct |
22 ms |
4360 KB |
Output is correct |
31 |
Correct |
37 ms |
4424 KB |
Output is correct |
32 |
Correct |
22 ms |
4176 KB |
Output is correct |
33 |
Correct |
24 ms |
4176 KB |
Output is correct |
34 |
Correct |
20 ms |
4336 KB |
Output is correct |
35 |
Correct |
18 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3920 KB |
Output is correct |
2 |
Correct |
3 ms |
3920 KB |
Output is correct |
3 |
Correct |
3 ms |
3920 KB |
Output is correct |
4 |
Correct |
3 ms |
3920 KB |
Output is correct |
5 |
Correct |
5 ms |
3920 KB |
Output is correct |
6 |
Correct |
5 ms |
4176 KB |
Output is correct |
7 |
Correct |
6 ms |
4176 KB |
Output is correct |
8 |
Correct |
9 ms |
4688 KB |
Output is correct |
9 |
Correct |
17 ms |
5704 KB |
Output is correct |
10 |
Correct |
52 ms |
8116 KB |
Output is correct |
11 |
Correct |
658 ms |
13896 KB |
Output is correct |
12 |
Correct |
124 ms |
13384 KB |
Output is correct |
13 |
Correct |
223 ms |
13640 KB |
Output is correct |
14 |
Correct |
326 ms |
14408 KB |
Output is correct |
15 |
Correct |
482 ms |
15368 KB |
Output is correct |
16 |
Correct |
247 ms |
16184 KB |
Output is correct |
17 |
Correct |
221 ms |
13384 KB |
Output is correct |
18 |
Correct |
311 ms |
13908 KB |
Output is correct |
19 |
Correct |
206 ms |
17124 KB |
Output is correct |
20 |
Correct |
119 ms |
15888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3920 KB |
Output is correct |
2 |
Correct |
3 ms |
3920 KB |
Output is correct |
3 |
Correct |
4 ms |
3924 KB |
Output is correct |
4 |
Correct |
4 ms |
3920 KB |
Output is correct |
5 |
Correct |
3 ms |
3920 KB |
Output is correct |
6 |
Correct |
4 ms |
3920 KB |
Output is correct |
7 |
Correct |
4 ms |
3920 KB |
Output is correct |
8 |
Correct |
4 ms |
4088 KB |
Output is correct |
9 |
Correct |
4 ms |
3920 KB |
Output is correct |
10 |
Correct |
3 ms |
3920 KB |
Output is correct |
11 |
Correct |
3 ms |
3920 KB |
Output is correct |
12 |
Correct |
3 ms |
3920 KB |
Output is correct |
13 |
Correct |
3 ms |
3920 KB |
Output is correct |
14 |
Correct |
4 ms |
3968 KB |
Output is correct |
15 |
Correct |
5 ms |
4176 KB |
Output is correct |
16 |
Correct |
4 ms |
3920 KB |
Output is correct |
17 |
Correct |
5 ms |
3920 KB |
Output is correct |
18 |
Correct |
6 ms |
4028 KB |
Output is correct |
19 |
Correct |
13 ms |
3920 KB |
Output is correct |
20 |
Correct |
21 ms |
4176 KB |
Output is correct |
21 |
Correct |
36 ms |
4176 KB |
Output is correct |
22 |
Correct |
32 ms |
4176 KB |
Output is correct |
23 |
Correct |
38 ms |
4176 KB |
Output is correct |
24 |
Correct |
41 ms |
4444 KB |
Output is correct |
25 |
Correct |
23 ms |
4176 KB |
Output is correct |
26 |
Correct |
25 ms |
4308 KB |
Output is correct |
27 |
Correct |
22 ms |
4176 KB |
Output is correct |
28 |
Correct |
22 ms |
4176 KB |
Output is correct |
29 |
Correct |
25 ms |
4176 KB |
Output is correct |
30 |
Correct |
22 ms |
4360 KB |
Output is correct |
31 |
Correct |
37 ms |
4424 KB |
Output is correct |
32 |
Correct |
22 ms |
4176 KB |
Output is correct |
33 |
Correct |
24 ms |
4176 KB |
Output is correct |
34 |
Correct |
20 ms |
4336 KB |
Output is correct |
35 |
Correct |
18 ms |
4176 KB |
Output is correct |
36 |
Correct |
3 ms |
3920 KB |
Output is correct |
37 |
Correct |
3 ms |
3920 KB |
Output is correct |
38 |
Correct |
3 ms |
3920 KB |
Output is correct |
39 |
Correct |
3 ms |
3920 KB |
Output is correct |
40 |
Correct |
5 ms |
3920 KB |
Output is correct |
41 |
Correct |
5 ms |
4176 KB |
Output is correct |
42 |
Correct |
6 ms |
4176 KB |
Output is correct |
43 |
Correct |
9 ms |
4688 KB |
Output is correct |
44 |
Correct |
17 ms |
5704 KB |
Output is correct |
45 |
Correct |
52 ms |
8116 KB |
Output is correct |
46 |
Correct |
658 ms |
13896 KB |
Output is correct |
47 |
Correct |
124 ms |
13384 KB |
Output is correct |
48 |
Correct |
223 ms |
13640 KB |
Output is correct |
49 |
Correct |
326 ms |
14408 KB |
Output is correct |
50 |
Correct |
482 ms |
15368 KB |
Output is correct |
51 |
Correct |
247 ms |
16184 KB |
Output is correct |
52 |
Correct |
221 ms |
13384 KB |
Output is correct |
53 |
Correct |
311 ms |
13908 KB |
Output is correct |
54 |
Correct |
206 ms |
17124 KB |
Output is correct |
55 |
Correct |
119 ms |
15888 KB |
Output is correct |
56 |
Correct |
84 ms |
4680 KB |
Output is correct |
57 |
Correct |
150 ms |
5448 KB |
Output is correct |
58 |
Correct |
160 ms |
6240 KB |
Output is correct |
59 |
Correct |
210 ms |
7924 KB |
Output is correct |
60 |
Correct |
284 ms |
8412 KB |
Output is correct |
61 |
Correct |
467 ms |
9540 KB |
Output is correct |
62 |
Correct |
749 ms |
11592 KB |
Output is correct |
63 |
Correct |
866 ms |
12036 KB |
Output is correct |
64 |
Correct |
773 ms |
13236 KB |
Output is correct |
65 |
Correct |
542 ms |
14272 KB |
Output is correct |
66 |
Correct |
816 ms |
14340 KB |
Output is correct |
67 |
Correct |
1298 ms |
14508 KB |
Output is correct |
68 |
Correct |
879 ms |
14444 KB |
Output is correct |
69 |
Correct |
635 ms |
16972 KB |
Output is correct |
70 |
Correct |
558 ms |
17740 KB |
Output is correct |
71 |
Correct |
590 ms |
17228 KB |
Output is correct |
72 |
Correct |
571 ms |
17140 KB |
Output is correct |
73 |
Correct |
621 ms |
17228 KB |
Output is correct |
74 |
Correct |
603 ms |
17164 KB |
Output is correct |
75 |
Correct |
637 ms |
17064 KB |
Output is correct |
76 |
Correct |
689 ms |
16876 KB |
Output is correct |
77 |
Correct |
682 ms |
17024 KB |
Output is correct |
78 |
Correct |
665 ms |
16976 KB |
Output is correct |
79 |
Correct |
699 ms |
16992 KB |
Output is correct |
80 |
Correct |
497 ms |
16716 KB |
Output is correct |