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;
#define int long long
typedef pair<int, int> pii;
const int MXN = 20;
int n, q, a[MXN], ans[MXN];
vector<pair<pii, int>> v[MXN];
int32_t main() {
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < q; i++) {
int t, l, r;
cin >> t >> l >> r;
v[t].push_back({{l, r}, i});
}
for (int i = 1; i <= n; i++) {
for (int j = n - 1; j > 0; j--) a[j] = max(a[j], a[j - 1]);
for (auto &j : v[i]) {
for (int k = j.first.first; k <= j.first.second; k++) ans[j.second] += a[k - 1];
}
}
for (int i = 0; i < q; i++) cout << ans[i] << endl;
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... |