#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define maxs 325
#define int long long
const int bl=315;
struct que{
int l,r,id;
};
vector<que> query[maxs][maxs];
int n,x[maxn],num[maxn],ans[maxn];
vector<int> p;
void add(int l,int r,int id,int res){
//cout << l << ' ' << r << ' ' << res << '\n';
for(int i=l;i<=r;i++){
if(i%bl==0 && i+bl-1<=r) i+=bl-1;
else{
num[x[i]]++;
res=max(res,num[x[i]]*p[x[i]]);
}
}
for(int i=l;i<=r;i++){
if(i%bl==0 && i+bl-1<=r) i+=bl-1;
else num[x[i]]--;
}
ans[id]=res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int q;cin >> n >> q;
for(int i=1;i<=n;i++){cin >> x[i];p.push_back(x[i]);}
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
for(int i=1;i<=n;i++) x[i]=lower_bound(p.begin(),p.end(),x[i])-p.begin();
for(int i=1;i<=q;i++){
int l,r;cin >> l >> r;
int down=(l-1)/bl+1,up=(r+1)/bl-1;
if(down>up) add(l,r,i,0);
else query[down][up].push_back({l,r,i});
}
for(int i=0;i<=n/bl;i++){
for(int j=0;j<(int)p.size();j++) num[j]=0;
int res=0;
for(int j=i;j<=n/bl;j++){
for(int k=max(1LL,j*bl);k<=min(n,j*bl+bl-1);k++){
num[x[k]]++;
res=max(res,p[x[k]]*num[x[k]]);
}
for(que v:query[i][j]) add(v.l,v.r,v.id,res);
}
}
for(int i=1;i<=q;i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2724 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
1 ms |
2808 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2900 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2804 KB |
Output is correct |
11 |
Correct |
2 ms |
2804 KB |
Output is correct |
12 |
Correct |
1 ms |
2812 KB |
Output is correct |
13 |
Correct |
1 ms |
2824 KB |
Output is correct |
14 |
Correct |
1 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2724 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
1 ms |
2808 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2900 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2804 KB |
Output is correct |
11 |
Correct |
2 ms |
2804 KB |
Output is correct |
12 |
Correct |
1 ms |
2812 KB |
Output is correct |
13 |
Correct |
1 ms |
2824 KB |
Output is correct |
14 |
Correct |
1 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2724 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2808 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
3 ms |
2952 KB |
Output is correct |
20 |
Correct |
4 ms |
3028 KB |
Output is correct |
21 |
Correct |
6 ms |
3156 KB |
Output is correct |
22 |
Correct |
8 ms |
3156 KB |
Output is correct |
23 |
Correct |
6 ms |
3208 KB |
Output is correct |
24 |
Correct |
6 ms |
3200 KB |
Output is correct |
25 |
Correct |
7 ms |
3208 KB |
Output is correct |
26 |
Correct |
6 ms |
3156 KB |
Output is correct |
27 |
Correct |
7 ms |
3284 KB |
Output is correct |
28 |
Correct |
8 ms |
3284 KB |
Output is correct |
29 |
Correct |
7 ms |
3284 KB |
Output is correct |
30 |
Correct |
6 ms |
3284 KB |
Output is correct |
31 |
Correct |
9 ms |
3264 KB |
Output is correct |
32 |
Correct |
7 ms |
3256 KB |
Output is correct |
33 |
Correct |
8 ms |
3188 KB |
Output is correct |
34 |
Correct |
7 ms |
3240 KB |
Output is correct |
35 |
Correct |
7 ms |
3204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
3 ms |
2812 KB |
Output is correct |
5 |
Correct |
2 ms |
2900 KB |
Output is correct |
6 |
Correct |
2 ms |
2900 KB |
Output is correct |
7 |
Correct |
3 ms |
3028 KB |
Output is correct |
8 |
Correct |
4 ms |
3248 KB |
Output is correct |
9 |
Correct |
9 ms |
3616 KB |
Output is correct |
10 |
Correct |
13 ms |
3976 KB |
Output is correct |
11 |
Correct |
60 ms |
7320 KB |
Output is correct |
12 |
Correct |
34 ms |
5204 KB |
Output is correct |
13 |
Correct |
62 ms |
6296 KB |
Output is correct |
14 |
Correct |
98 ms |
7272 KB |
Output is correct |
15 |
Correct |
78 ms |
8728 KB |
Output is correct |
16 |
Correct |
140 ms |
8988 KB |
Output is correct |
17 |
Correct |
68 ms |
6232 KB |
Output is correct |
18 |
Correct |
103 ms |
9284 KB |
Output is correct |
19 |
Correct |
123 ms |
11652 KB |
Output is correct |
20 |
Correct |
63 ms |
7232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2724 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
1 ms |
2808 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2900 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2804 KB |
Output is correct |
11 |
Correct |
2 ms |
2804 KB |
Output is correct |
12 |
Correct |
1 ms |
2812 KB |
Output is correct |
13 |
Correct |
1 ms |
2824 KB |
Output is correct |
14 |
Correct |
1 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2724 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2808 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
3 ms |
2952 KB |
Output is correct |
20 |
Correct |
4 ms |
3028 KB |
Output is correct |
21 |
Correct |
6 ms |
3156 KB |
Output is correct |
22 |
Correct |
8 ms |
3156 KB |
Output is correct |
23 |
Correct |
6 ms |
3208 KB |
Output is correct |
24 |
Correct |
6 ms |
3200 KB |
Output is correct |
25 |
Correct |
7 ms |
3208 KB |
Output is correct |
26 |
Correct |
6 ms |
3156 KB |
Output is correct |
27 |
Correct |
7 ms |
3284 KB |
Output is correct |
28 |
Correct |
8 ms |
3284 KB |
Output is correct |
29 |
Correct |
7 ms |
3284 KB |
Output is correct |
30 |
Correct |
6 ms |
3284 KB |
Output is correct |
31 |
Correct |
9 ms |
3264 KB |
Output is correct |
32 |
Correct |
7 ms |
3256 KB |
Output is correct |
33 |
Correct |
8 ms |
3188 KB |
Output is correct |
34 |
Correct |
7 ms |
3240 KB |
Output is correct |
35 |
Correct |
7 ms |
3204 KB |
Output is correct |
36 |
Correct |
2 ms |
2772 KB |
Output is correct |
37 |
Correct |
2 ms |
2772 KB |
Output is correct |
38 |
Correct |
2 ms |
2772 KB |
Output is correct |
39 |
Correct |
3 ms |
2812 KB |
Output is correct |
40 |
Correct |
2 ms |
2900 KB |
Output is correct |
41 |
Correct |
2 ms |
2900 KB |
Output is correct |
42 |
Correct |
3 ms |
3028 KB |
Output is correct |
43 |
Correct |
4 ms |
3248 KB |
Output is correct |
44 |
Correct |
9 ms |
3616 KB |
Output is correct |
45 |
Correct |
13 ms |
3976 KB |
Output is correct |
46 |
Correct |
60 ms |
7320 KB |
Output is correct |
47 |
Correct |
34 ms |
5204 KB |
Output is correct |
48 |
Correct |
62 ms |
6296 KB |
Output is correct |
49 |
Correct |
98 ms |
7272 KB |
Output is correct |
50 |
Correct |
78 ms |
8728 KB |
Output is correct |
51 |
Correct |
140 ms |
8988 KB |
Output is correct |
52 |
Correct |
68 ms |
6232 KB |
Output is correct |
53 |
Correct |
103 ms |
9284 KB |
Output is correct |
54 |
Correct |
123 ms |
11652 KB |
Output is correct |
55 |
Correct |
63 ms |
7232 KB |
Output is correct |
56 |
Correct |
11 ms |
3588 KB |
Output is correct |
57 |
Correct |
23 ms |
4524 KB |
Output is correct |
58 |
Correct |
40 ms |
5468 KB |
Output is correct |
59 |
Correct |
56 ms |
6336 KB |
Output is correct |
60 |
Correct |
84 ms |
7324 KB |
Output is correct |
61 |
Correct |
87 ms |
8256 KB |
Output is correct |
62 |
Correct |
93 ms |
9108 KB |
Output is correct |
63 |
Correct |
109 ms |
10172 KB |
Output is correct |
64 |
Correct |
127 ms |
11092 KB |
Output is correct |
65 |
Correct |
234 ms |
11292 KB |
Output is correct |
66 |
Correct |
145 ms |
11420 KB |
Output is correct |
67 |
Correct |
143 ms |
11496 KB |
Output is correct |
68 |
Correct |
167 ms |
11628 KB |
Output is correct |
69 |
Correct |
190 ms |
11928 KB |
Output is correct |
70 |
Correct |
198 ms |
12128 KB |
Output is correct |
71 |
Correct |
196 ms |
12100 KB |
Output is correct |
72 |
Correct |
189 ms |
11984 KB |
Output is correct |
73 |
Correct |
204 ms |
12036 KB |
Output is correct |
74 |
Correct |
184 ms |
11944 KB |
Output is correct |
75 |
Correct |
183 ms |
11920 KB |
Output is correct |
76 |
Correct |
185 ms |
11904 KB |
Output is correct |
77 |
Correct |
190 ms |
11924 KB |
Output is correct |
78 |
Correct |
182 ms |
11880 KB |
Output is correct |
79 |
Correct |
213 ms |
11876 KB |
Output is correct |
80 |
Correct |
247 ms |
12064 KB |
Output is correct |