This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#ifndef LOCAL
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937 mt(123);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cout << fixed << setprecision(30);
init();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
const int N = 200200, K = 400;
int a[N];
ll sm[K][N];
void solve() {
int n, q;
cin >> n >> q;
vector<pair<int, pair<int, int>>> st;
for (int i = 0; i < n; i++) {
cin >> a[i];
sm[0][i + 1] = a[i];
if (st.empty() || a[i] > st.back().x) {
st.emplace_back(a[i], make_pair(i, 0));
}
}
vector<pair<ll, int>> good;
vector<pair<int, int>> bad;
for (int i = 0; i < st.size(); i++) {
if (i + 1 < st.size()) {
st[i].y.y = st[i + 1].y.x - st[i].y.x;
} else {
st[i].y.y = n - st[i].y.x;
}
if (st[i].y.y < K) {
good.emplace_back(1ll * st[i].y.y * st[i].x, st[i].y.x);
} else {
bad.push_back(st[i].y);
}
}
for (int l = 1; l < K; l++) {
for (int i = 1; i <= n; i++) {
sm[l][i] = max(sm[l - 1][i], sm[l - 1][i - 1]);
}
}
for (int l = 0; l < K; l++) {
for (int i = 1; i <= n; i++) {
sm[l][i] += sm[l][i - 1];
}
}
while (q--) {
int t, l, r;
cin >> t >> l >> r; l--; r--;
if (t < K) {
cout << sm[t][r + 1] - sm[t][l] << '\n';
continue;
}
}
}
Compilation message (stderr)
ho_t5.cpp: In function 'void solve()':
ho_t5.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < st.size(); i++) {
| ~~^~~~~~~~~~~
ho_t5.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if (i + 1 < st.size()) {
| ~~~~~~^~~~~~~~~~~
# | 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... |