#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 300005
#define modulo 1000000007
#define int long long
const int INF = 2e18 + 7;
int arr[N], cnt[N];
int f(int sz, int n, int mask, int ind)
{
if (ind > sz) return 0;
int ans = INF;
for (int i = 0; i < n; i++)
{
if (mask & (1<<i)) continue;
int fin = ind + cnt[i + 1] - 1;
int tmp = (sz * (sz + 1)) / 2 - (((ind - 1) * ind) / 2 + ((sz - fin) * (sz - fin + 1)) / 2);
ans = min(ans, tmp + f(sz, n, mask | (1<<i), fin + 1));
}
return ans;
}
int32_t main()
{
fastio();
int n, q;
cin>>n>>q;
for (int i = 1; i <= n; i++)
cin>>arr[i];
while(q--)
{
memset(cnt, 0, sizeof(cnt));
int l, r;
cin>>l>>r;
map<int, int> val;
int counter = 1;
for (int i = l; i <= r; i++)
{
cnt[arr[i]]++;
}
int res = f(r - l + 1, 11, 0, 1);
cout<<res<<endl;
}
}
Compilation message
diversity.cpp: In function 'int32_t main()':
diversity.cpp:47:7: warning: unused variable 'counter' [-Wunused-variable]
47 | int counter = 1;
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
2668 KB |
Output is correct |
2 |
Correct |
446 ms |
2668 KB |
Output is correct |
3 |
Correct |
664 ms |
2672 KB |
Output is correct |
4 |
Correct |
868 ms |
2664 KB |
Output is correct |
5 |
Correct |
1127 ms |
2664 KB |
Output is correct |
6 |
Correct |
1360 ms |
2660 KB |
Output is correct |
7 |
Correct |
1506 ms |
2660 KB |
Output is correct |
8 |
Correct |
1589 ms |
2660 KB |
Output is correct |
9 |
Correct |
1689 ms |
2656 KB |
Output is correct |
10 |
Correct |
1762 ms |
2660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1178 ms |
2664 KB |
Output is correct |
2 |
Correct |
1417 ms |
2664 KB |
Output is correct |
3 |
Correct |
1553 ms |
2772 KB |
Output is correct |
4 |
Correct |
1555 ms |
3640 KB |
Output is correct |
5 |
Correct |
1912 ms |
4612 KB |
Output is correct |
6 |
Correct |
1926 ms |
5676 KB |
Output is correct |
7 |
Correct |
1946 ms |
5604 KB |
Output is correct |
8 |
Correct |
1798 ms |
5624 KB |
Output is correct |
9 |
Correct |
1804 ms |
5628 KB |
Output is correct |
10 |
Correct |
1706 ms |
5656 KB |
Output is correct |
11 |
Correct |
1659 ms |
5640 KB |
Output is correct |
12 |
Correct |
1760 ms |
5676 KB |
Output is correct |
13 |
Correct |
1811 ms |
5644 KB |
Output is correct |
14 |
Correct |
1713 ms |
5632 KB |
Output is correct |
15 |
Correct |
1675 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1178 ms |
2664 KB |
Output is correct |
2 |
Correct |
1417 ms |
2664 KB |
Output is correct |
3 |
Correct |
1553 ms |
2772 KB |
Output is correct |
4 |
Correct |
1555 ms |
3640 KB |
Output is correct |
5 |
Correct |
1912 ms |
4612 KB |
Output is correct |
6 |
Correct |
1926 ms |
5676 KB |
Output is correct |
7 |
Correct |
1946 ms |
5604 KB |
Output is correct |
8 |
Correct |
1798 ms |
5624 KB |
Output is correct |
9 |
Correct |
1804 ms |
5628 KB |
Output is correct |
10 |
Correct |
1706 ms |
5656 KB |
Output is correct |
11 |
Correct |
1659 ms |
5640 KB |
Output is correct |
12 |
Correct |
1760 ms |
5676 KB |
Output is correct |
13 |
Correct |
1811 ms |
5644 KB |
Output is correct |
14 |
Correct |
1713 ms |
5632 KB |
Output is correct |
15 |
Correct |
1675 ms |
5636 KB |
Output is correct |
16 |
Incorrect |
2442 ms |
2664 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1178 ms |
2664 KB |
Output is correct |
2 |
Correct |
1417 ms |
2664 KB |
Output is correct |
3 |
Correct |
1553 ms |
2772 KB |
Output is correct |
4 |
Correct |
1555 ms |
3640 KB |
Output is correct |
5 |
Correct |
1912 ms |
4612 KB |
Output is correct |
6 |
Correct |
1926 ms |
5676 KB |
Output is correct |
7 |
Correct |
1946 ms |
5604 KB |
Output is correct |
8 |
Correct |
1798 ms |
5624 KB |
Output is correct |
9 |
Correct |
1804 ms |
5628 KB |
Output is correct |
10 |
Correct |
1706 ms |
5656 KB |
Output is correct |
11 |
Correct |
1659 ms |
5640 KB |
Output is correct |
12 |
Correct |
1760 ms |
5676 KB |
Output is correct |
13 |
Correct |
1811 ms |
5644 KB |
Output is correct |
14 |
Correct |
1713 ms |
5632 KB |
Output is correct |
15 |
Correct |
1675 ms |
5636 KB |
Output is correct |
16 |
Incorrect |
2442 ms |
2664 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
2668 KB |
Output is correct |
2 |
Correct |
446 ms |
2668 KB |
Output is correct |
3 |
Correct |
664 ms |
2672 KB |
Output is correct |
4 |
Correct |
868 ms |
2664 KB |
Output is correct |
5 |
Correct |
1127 ms |
2664 KB |
Output is correct |
6 |
Correct |
1360 ms |
2660 KB |
Output is correct |
7 |
Correct |
1506 ms |
2660 KB |
Output is correct |
8 |
Correct |
1589 ms |
2660 KB |
Output is correct |
9 |
Correct |
1689 ms |
2656 KB |
Output is correct |
10 |
Correct |
1762 ms |
2660 KB |
Output is correct |
11 |
Correct |
1178 ms |
2664 KB |
Output is correct |
12 |
Correct |
1417 ms |
2664 KB |
Output is correct |
13 |
Correct |
1553 ms |
2772 KB |
Output is correct |
14 |
Correct |
1555 ms |
3640 KB |
Output is correct |
15 |
Correct |
1912 ms |
4612 KB |
Output is correct |
16 |
Correct |
1926 ms |
5676 KB |
Output is correct |
17 |
Correct |
1946 ms |
5604 KB |
Output is correct |
18 |
Correct |
1798 ms |
5624 KB |
Output is correct |
19 |
Correct |
1804 ms |
5628 KB |
Output is correct |
20 |
Correct |
1706 ms |
5656 KB |
Output is correct |
21 |
Correct |
1659 ms |
5640 KB |
Output is correct |
22 |
Correct |
1760 ms |
5676 KB |
Output is correct |
23 |
Correct |
1811 ms |
5644 KB |
Output is correct |
24 |
Correct |
1713 ms |
5632 KB |
Output is correct |
25 |
Correct |
1675 ms |
5636 KB |
Output is correct |
26 |
Incorrect |
2442 ms |
2664 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
2668 KB |
Output is correct |
2 |
Correct |
446 ms |
2668 KB |
Output is correct |
3 |
Correct |
664 ms |
2672 KB |
Output is correct |
4 |
Correct |
868 ms |
2664 KB |
Output is correct |
5 |
Correct |
1127 ms |
2664 KB |
Output is correct |
6 |
Correct |
1360 ms |
2660 KB |
Output is correct |
7 |
Correct |
1506 ms |
2660 KB |
Output is correct |
8 |
Correct |
1589 ms |
2660 KB |
Output is correct |
9 |
Correct |
1689 ms |
2656 KB |
Output is correct |
10 |
Correct |
1762 ms |
2660 KB |
Output is correct |
11 |
Correct |
1178 ms |
2664 KB |
Output is correct |
12 |
Correct |
1417 ms |
2664 KB |
Output is correct |
13 |
Correct |
1553 ms |
2772 KB |
Output is correct |
14 |
Correct |
1555 ms |
3640 KB |
Output is correct |
15 |
Correct |
1912 ms |
4612 KB |
Output is correct |
16 |
Correct |
1926 ms |
5676 KB |
Output is correct |
17 |
Correct |
1946 ms |
5604 KB |
Output is correct |
18 |
Correct |
1798 ms |
5624 KB |
Output is correct |
19 |
Correct |
1804 ms |
5628 KB |
Output is correct |
20 |
Correct |
1706 ms |
5656 KB |
Output is correct |
21 |
Correct |
1659 ms |
5640 KB |
Output is correct |
22 |
Correct |
1760 ms |
5676 KB |
Output is correct |
23 |
Correct |
1811 ms |
5644 KB |
Output is correct |
24 |
Correct |
1713 ms |
5632 KB |
Output is correct |
25 |
Correct |
1675 ms |
5636 KB |
Output is correct |
26 |
Incorrect |
2442 ms |
2664 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |