#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;
typedef long long llong;
const int MAXN = 3e5 + 10;
int n, q;
int b[MAXN];
int a[MAXN];
int m;
vector < int > pos;
void read()
{
cin >> n >> q;
for(int i = 1; i <= n; i++)
{
cin >> b[i];
}
assert(q == 1);
int left, right;
cin >> left >> right;
m = right - left + 1;
for(int i = 1; i <= m; i++)
{
a[i] = b[left + i - 1];
}
}
void solve()
{
sort(a + 1, a + 1 + m);
for(int i = 2; i <= m; i++)
{
if(a[i] != a[i - 1])
{
pos.push_back(i - 1);
}
}
pos.push_back(m);
int ptr = 0;
llong ans = 0;
for(int i = 1; i <= m; i++)
{
while(ptr < pos.size() && pos[ptr] < i)
ptr++;
int cnt = 1;
int last = i - 1;
for(int j = ptr; j < pos.size(); j++)
{
int len = pos[j] - last;
ans += 1LL * len * cnt;
cnt++;
last = pos[j];
}
}
cout << ans << endl;
}
int main()
{
read();
solve();
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |