# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
952974 | Sacharlemagne | Diversity (CEOI21_diversity) | C++17 | 7015 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
//ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,q; cin >> n >> q;
vector<int> vv(n); for (int i = 0; i<n; ++i) cin >> vv[i];
while (q--) {
long long fin = 4e18;
int L, R;
cin >> L >> R;
--L; --R;
vector<int> v(R-L+1); for (int i = 0; i<R-L+1; ++i) v[i] = vv[i+L];
do {
ll ans = 0;
map<ll,ll> last;
for (ll i = 0; i<v.size(); ++i) {
int bef = last[v[i]];
ans += (i-bef+1)*(v.size()-i);
last[v[i]] = i+1;
}
fin = min(fin, ans);
} while (next_permutation(v.begin(), v.end()));
cout << fin << '\n';
}
return 0;
}
/*
*
*/
Compilation message (stderr)
# | 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... |