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;
const int MAX=2*1e5+7;
ll ogien[MAX];
ll odp[MAX];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, q, t, l, r;
cin >> n >> q;
vector<pair<pair<ll, ll>, pair<ll, ll>>> zapytania;
for (int i=0; i<n; i++){
cin >> ogien[i+1];
}
for (int i=0; i<q; i++){
cin >> t >> l >> r;
zapytania.push_back({{t, i}, {l, r}});
}
sort(zapytania.begin(), zapytania.end());
ll it = 0;
for (int i=1; i<=n; i++){
for(int j=n; j>0; --j) ogien[j] = max(ogien[j-1], ogien[j]);
while(zapytania[it].first.first==i){
ll suma=0;
for (int j=zapytania[it].second.first; j<=zapytania[it].second.second; j++) suma += ogien[j];
odp[zapytania[it].first.second] = suma;
it++;
}
}
for (int i=0; i<q; i++) cout << odp[i] << "\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... |