/* ************************************************************************** */
/* */
/* ::: ::: ::: */
/* Problem Number: 17731 :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: js9028 <boj.kr/u/js9028> +#+ +#+ +#+ */
/* +#+ +#+ +#+ */
/* https://boj.kr/17731 #+# #+# #+# */
/* Solved: 2024/09/24 14:38:32 by js9028 ### ### ##.kr */
/* */
/* ************************************************************************** */
#include <bits/stdc++.h>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;
int n, q;
int sq;
int idx[100055];
ll arr[100055];
vector<ll> num;
vector<array<int, 3>> query;
ll ans[100055];
int cnt[100055];
map<int, int> mp;
void ADD(int i)
{
i = idx[i];
if (mp.find(i) == mp.end())
mp[i] = cnt[i];
cnt[i]++;
}
void SUB(int i)
{
i = idx[i];
if (mp.find(i) == mp.end())
mp[i] = cnt[i];
cnt[i]--;
}
set<pair<ll, int>> st;
void solve()
{
int s = 1, e = 0;
for (auto [l, r, q] : query)
{
mp.clear();
while (e < r)
e++, ADD(e);
while (s > l)
s--, ADD(s);
while (s < l)
SUB(s), s++;
while (e > r)
SUB(e), e--;
for (auto &p : mp)
{
if (p.second == cnt[p.first])
continue;
else
{
st.erase({num[p.first] * p.second, p.first});
st.insert({num[p.first] * cnt[p.first], p.first});
}
}
ans[q] = (--st.end())->first;
}
}
int main()
{
fastio;
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
num.push_back(arr[i]);
}
for (int i = 0; i < q; i++)
{
int l, r;
cin >> l >> r;
query.push_back({l, r, i});
}
sort(num.begin(), num.end());
for(int i = 1;i <=n;i++){
idx[i] = lower_bound(num.begin(), num.end(), arr[i]) - num.begin();
}
sq = sqrt(n);
sort(query.begin(), query.end(), [](auto &a, auto &b)
{
int sa = a[0] / sq, sb = b[0] / sq;
if(sa == sb) return a[1] < b[1];
return sa < sb; });
solve();
for (int i = 0; i < q; i++)
{
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2524 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2524 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
13 ms |
2396 KB |
Output is correct |
20 |
Correct |
35 ms |
2648 KB |
Output is correct |
21 |
Correct |
53 ms |
2652 KB |
Output is correct |
22 |
Correct |
69 ms |
2652 KB |
Output is correct |
23 |
Correct |
30 ms |
2652 KB |
Output is correct |
24 |
Correct |
34 ms |
2812 KB |
Output is correct |
25 |
Correct |
116 ms |
2880 KB |
Output is correct |
26 |
Correct |
114 ms |
2900 KB |
Output is correct |
27 |
Correct |
109 ms |
2896 KB |
Output is correct |
28 |
Correct |
107 ms |
2868 KB |
Output is correct |
29 |
Correct |
97 ms |
2648 KB |
Output is correct |
30 |
Correct |
102 ms |
2840 KB |
Output is correct |
31 |
Correct |
36 ms |
2896 KB |
Output is correct |
32 |
Correct |
7 ms |
2904 KB |
Output is correct |
33 |
Correct |
100 ms |
2852 KB |
Output is correct |
34 |
Correct |
118 ms |
2920 KB |
Output is correct |
35 |
Correct |
129 ms |
2976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
5 ms |
2616 KB |
Output is correct |
8 |
Correct |
8 ms |
2908 KB |
Output is correct |
9 |
Correct |
21 ms |
3580 KB |
Output is correct |
10 |
Correct |
6 ms |
3296 KB |
Output is correct |
11 |
Correct |
58 ms |
7372 KB |
Output is correct |
12 |
Correct |
28 ms |
4312 KB |
Output is correct |
13 |
Correct |
89 ms |
5316 KB |
Output is correct |
14 |
Correct |
109 ms |
8648 KB |
Output is correct |
15 |
Correct |
103 ms |
11200 KB |
Output is correct |
16 |
Correct |
110 ms |
12488 KB |
Output is correct |
17 |
Correct |
30 ms |
4916 KB |
Output is correct |
18 |
Correct |
51 ms |
7616 KB |
Output is correct |
19 |
Correct |
80 ms |
13440 KB |
Output is correct |
20 |
Correct |
59 ms |
13772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2524 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
13 ms |
2396 KB |
Output is correct |
20 |
Correct |
35 ms |
2648 KB |
Output is correct |
21 |
Correct |
53 ms |
2652 KB |
Output is correct |
22 |
Correct |
69 ms |
2652 KB |
Output is correct |
23 |
Correct |
30 ms |
2652 KB |
Output is correct |
24 |
Correct |
34 ms |
2812 KB |
Output is correct |
25 |
Correct |
116 ms |
2880 KB |
Output is correct |
26 |
Correct |
114 ms |
2900 KB |
Output is correct |
27 |
Correct |
109 ms |
2896 KB |
Output is correct |
28 |
Correct |
107 ms |
2868 KB |
Output is correct |
29 |
Correct |
97 ms |
2648 KB |
Output is correct |
30 |
Correct |
102 ms |
2840 KB |
Output is correct |
31 |
Correct |
36 ms |
2896 KB |
Output is correct |
32 |
Correct |
7 ms |
2904 KB |
Output is correct |
33 |
Correct |
100 ms |
2852 KB |
Output is correct |
34 |
Correct |
118 ms |
2920 KB |
Output is correct |
35 |
Correct |
129 ms |
2976 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
2 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
5 ms |
2616 KB |
Output is correct |
43 |
Correct |
8 ms |
2908 KB |
Output is correct |
44 |
Correct |
21 ms |
3580 KB |
Output is correct |
45 |
Correct |
6 ms |
3296 KB |
Output is correct |
46 |
Correct |
58 ms |
7372 KB |
Output is correct |
47 |
Correct |
28 ms |
4312 KB |
Output is correct |
48 |
Correct |
89 ms |
5316 KB |
Output is correct |
49 |
Correct |
109 ms |
8648 KB |
Output is correct |
50 |
Correct |
103 ms |
11200 KB |
Output is correct |
51 |
Correct |
110 ms |
12488 KB |
Output is correct |
52 |
Correct |
30 ms |
4916 KB |
Output is correct |
53 |
Correct |
51 ms |
7616 KB |
Output is correct |
54 |
Correct |
80 ms |
13440 KB |
Output is correct |
55 |
Correct |
59 ms |
13772 KB |
Output is correct |
56 |
Correct |
105 ms |
3152 KB |
Output is correct |
57 |
Correct |
636 ms |
3484 KB |
Output is correct |
58 |
Correct |
1867 ms |
4548 KB |
Output is correct |
59 |
Correct |
3723 ms |
5712 KB |
Output is correct |
60 |
Execution timed out |
4025 ms |
6216 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |