#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100050
#define sqrtn 320
#define f first
#define s second
vector<vector<pair<int,pair<int,int> > > > queries(sqrtn);
vector<int> cnt(maxn,0);
vector<int> ans(maxn,0);
vector<int> isspecial(maxn,0);
vector<int> vect1;
vector<int> compress;
int currmx = 0;
void rem(int a){
cnt[a]--;
}
void add(int a){
cnt[a]++;
if(isspecial[a]==0){
currmx = max(currmx,cnt[a]*compress[a]);
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
int input,a,b;
for(int i=0;i<n;i++){
cin >> input;
vect1.push_back(input);
compress.push_back(input);
}
sort(compress.begin(),compress.end());
for(int i=0;i<n;i++){
vect1[i] = lower_bound(compress.begin(),compress.end(),vect1[i])-compress.begin();
}
for(int i=0;i<m;i++){
cin >> a >> b;
a--,b--;
queries[a/sqrtn].push_back({b,{a,i}});
}
for(int i=0;i<sqrtn;i++){
sort(queries[i].begin(),queries[i].end());
if(queries[i].size()==0){
continue;
}
for(int j=0;j<maxn;j++){
cnt[j] = 0;
isspecial[j] = 0;
}
currmx = 0;
int currpos = (i+1)*sqrtn-1;
int l = 0,r = -1;
for(int j=sqrtn*i;j<=min(n-1,currpos);j++){
isspecial[vect1[j]] = 1;
}
for(int j=0;j<=min(n-1,currpos);j++){
rem(vect1[j]);
}
for(auto k:queries[i]){
for(int j=k.s.f;j<=min(n-1,currpos);j++){
add(vect1[j]);
}
while(r<k.f){
r++;
add(vect1[r]);
}
int currans = currmx;
for(int j=i*sqrtn;j<=min(n-1,currpos);j++){
currans = max(currans,cnt[vect1[j]]*compress[vect1[j]]);
}
ans[k.s.s] = currans;
for(int j=k.s.f;j<=min(n-1,currpos);j++){
rem(vect1[j]);
}
}
}
for(int i=0;i<m;i++){
cout << ans[i] << "\n";
}
}
Compilation message
historic.cpp: In function 'int32_t main()':
historic.cpp:55:9: warning: unused variable 'l' [-Wunused-variable]
55 | int l = 0,r = -1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2652 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
3 ms |
2676 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2652 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
3 ms |
2676 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2764 KB |
Output is correct |
19 |
Correct |
8 ms |
2892 KB |
Output is correct |
20 |
Correct |
12 ms |
2964 KB |
Output is correct |
21 |
Correct |
16 ms |
3020 KB |
Output is correct |
22 |
Correct |
17 ms |
3044 KB |
Output is correct |
23 |
Correct |
16 ms |
3020 KB |
Output is correct |
24 |
Correct |
15 ms |
3048 KB |
Output is correct |
25 |
Correct |
21 ms |
3052 KB |
Output is correct |
26 |
Correct |
18 ms |
3076 KB |
Output is correct |
27 |
Correct |
18 ms |
3076 KB |
Output is correct |
28 |
Correct |
18 ms |
3092 KB |
Output is correct |
29 |
Correct |
18 ms |
3148 KB |
Output is correct |
30 |
Correct |
22 ms |
3076 KB |
Output is correct |
31 |
Correct |
16 ms |
3020 KB |
Output is correct |
32 |
Correct |
16 ms |
3092 KB |
Output is correct |
33 |
Correct |
18 ms |
3084 KB |
Output is correct |
34 |
Correct |
20 ms |
3020 KB |
Output is correct |
35 |
Correct |
16 ms |
3020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
5 ms |
2764 KB |
Output is correct |
6 |
Correct |
5 ms |
2764 KB |
Output is correct |
7 |
Correct |
8 ms |
3028 KB |
Output is correct |
8 |
Correct |
8 ms |
3020 KB |
Output is correct |
9 |
Correct |
27 ms |
3488 KB |
Output is correct |
10 |
Correct |
52 ms |
3980 KB |
Output is correct |
11 |
Correct |
372 ms |
9520 KB |
Output is correct |
12 |
Correct |
82 ms |
5228 KB |
Output is correct |
13 |
Correct |
349 ms |
6356 KB |
Output is correct |
14 |
Correct |
399 ms |
8444 KB |
Output is correct |
15 |
Correct |
580 ms |
11444 KB |
Output is correct |
16 |
Correct |
308 ms |
8028 KB |
Output is correct |
17 |
Correct |
173 ms |
6136 KB |
Output is correct |
18 |
Correct |
333 ms |
9152 KB |
Output is correct |
19 |
Correct |
364 ms |
9816 KB |
Output is correct |
20 |
Correct |
119 ms |
6200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2652 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
3 ms |
2676 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2764 KB |
Output is correct |
19 |
Correct |
8 ms |
2892 KB |
Output is correct |
20 |
Correct |
12 ms |
2964 KB |
Output is correct |
21 |
Correct |
16 ms |
3020 KB |
Output is correct |
22 |
Correct |
17 ms |
3044 KB |
Output is correct |
23 |
Correct |
16 ms |
3020 KB |
Output is correct |
24 |
Correct |
15 ms |
3048 KB |
Output is correct |
25 |
Correct |
21 ms |
3052 KB |
Output is correct |
26 |
Correct |
18 ms |
3076 KB |
Output is correct |
27 |
Correct |
18 ms |
3076 KB |
Output is correct |
28 |
Correct |
18 ms |
3092 KB |
Output is correct |
29 |
Correct |
18 ms |
3148 KB |
Output is correct |
30 |
Correct |
22 ms |
3076 KB |
Output is correct |
31 |
Correct |
16 ms |
3020 KB |
Output is correct |
32 |
Correct |
16 ms |
3092 KB |
Output is correct |
33 |
Correct |
18 ms |
3084 KB |
Output is correct |
34 |
Correct |
20 ms |
3020 KB |
Output is correct |
35 |
Correct |
16 ms |
3020 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
3 ms |
2688 KB |
Output is correct |
39 |
Correct |
3 ms |
2636 KB |
Output is correct |
40 |
Correct |
5 ms |
2764 KB |
Output is correct |
41 |
Correct |
5 ms |
2764 KB |
Output is correct |
42 |
Correct |
8 ms |
3028 KB |
Output is correct |
43 |
Correct |
8 ms |
3020 KB |
Output is correct |
44 |
Correct |
27 ms |
3488 KB |
Output is correct |
45 |
Correct |
52 ms |
3980 KB |
Output is correct |
46 |
Correct |
372 ms |
9520 KB |
Output is correct |
47 |
Correct |
82 ms |
5228 KB |
Output is correct |
48 |
Correct |
349 ms |
6356 KB |
Output is correct |
49 |
Correct |
399 ms |
8444 KB |
Output is correct |
50 |
Correct |
580 ms |
11444 KB |
Output is correct |
51 |
Correct |
308 ms |
8028 KB |
Output is correct |
52 |
Correct |
173 ms |
6136 KB |
Output is correct |
53 |
Correct |
333 ms |
9152 KB |
Output is correct |
54 |
Correct |
364 ms |
9816 KB |
Output is correct |
55 |
Correct |
119 ms |
6200 KB |
Output is correct |
56 |
Correct |
31 ms |
3436 KB |
Output is correct |
57 |
Correct |
83 ms |
4172 KB |
Output is correct |
58 |
Correct |
132 ms |
4964 KB |
Output is correct |
59 |
Correct |
204 ms |
5816 KB |
Output is correct |
60 |
Correct |
252 ms |
6652 KB |
Output is correct |
61 |
Correct |
338 ms |
7708 KB |
Output is correct |
62 |
Correct |
478 ms |
8556 KB |
Output is correct |
63 |
Correct |
396 ms |
9496 KB |
Output is correct |
64 |
Correct |
470 ms |
10440 KB |
Output is correct |
65 |
Correct |
499 ms |
10496 KB |
Output is correct |
66 |
Correct |
547 ms |
10696 KB |
Output is correct |
67 |
Correct |
686 ms |
10800 KB |
Output is correct |
68 |
Correct |
703 ms |
10984 KB |
Output is correct |
69 |
Correct |
702 ms |
10924 KB |
Output is correct |
70 |
Correct |
752 ms |
11152 KB |
Output is correct |
71 |
Correct |
677 ms |
11132 KB |
Output is correct |
72 |
Correct |
706 ms |
10980 KB |
Output is correct |
73 |
Correct |
701 ms |
11136 KB |
Output is correct |
74 |
Correct |
699 ms |
11104 KB |
Output is correct |
75 |
Correct |
710 ms |
10908 KB |
Output is correct |
76 |
Correct |
726 ms |
10964 KB |
Output is correct |
77 |
Correct |
744 ms |
11128 KB |
Output is correct |
78 |
Correct |
685 ms |
11048 KB |
Output is correct |
79 |
Correct |
666 ms |
11016 KB |
Output is correct |
80 |
Correct |
517 ms |
11368 KB |
Output is correct |