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;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, q; cin >> n >> q;
vector<int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
for (int i = 0; i < q; ++i) {
int l, r; cin >> l >> r;
l--;
vector<int> v;
v.reserve(r - l);
int s = r - l;
for (int j = l; j < r; ++j) {
v.push_back(arr[j]);
}
std::sort(v.begin(), v.end());
int ans = 0;
for (int j = 0; j < s; ++j) {
set<int> num;
for (int k = j; k < s; ++k) {
num.insert(v[k]);
ans += num.size();
}
}
cout << ans << "\n";
}
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... |