This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
mt19937 __gen = mt19937(__rd()); \
uniform_int_distribution<int> __dis(1, 1E8); \
auto rnd = bind(__dis, __gen)
const int INF = 1E18;
const int mod = 1E9 + 7;
int32_t main() {
fastIO();
int n, q;
cin >> n >> q;
int v[n];
for (int i = 0; i < n; ++i) cin >> v[i];
auto Query_Max = [&](int L, int R) -> int {
return *max_element(v + L, v + R + 1);
};
int t[q], l[q], r[q];
for (int i = 0; i < q; ++i) cin >> t[i] >> l[i] >> r[i], --l[i], --r[i];
int fl_sub2 = 1, fl_sub3 = 1, fl_sub4 = 1;
for (int i = 0; i < q; ++i) {
if (t[i] != t[0]) fl_sub2 = 0;
if (l[i] != r[i]) fl_sub3 = 0;
}
for (int i = 0; i < n; ++i) {
if (v[i] > 2) fl_sub4 = 0;
}
if (fl_sub2) {
deque<pii> deq; /// (val, time)
for (int i = 0; i < n; ++i) {
while (!deq.empty() and deq.back().X <= v[i]) deq.pop_back();
deq.push_back({v[i], i});
if (deq.front().Y == i - t[0] - 1) deq.pop_front();
v[i] = deq.front().X;
}
partial_sum(v, v + n, v);
for (int i = 0; i < q; ++i) {
cout << v[r[i]] - (l[i] == 0 ? 0LL : v[l[i] - 1]) << "\n";
}
return 0;
}
if (fl_sub3) {
int st[18][n];
for (int i = 0; i < n; ++i) st[0][i] = v[i];
for (int lay = 1; lay < 18; ++lay) {
for (int i = 0; i+(1<<lay-1) < n; ++i) {
st[lay][i] = max(st[lay - 1][i], st[lay - 1][i + (1 << lay-1)]);
}
}
for (int i = 0; i < q; ++i) {
int _l = max(0LL, l[i] - t[i]), _r = l[i];
}
}
for (int i = 0; i < q; ++i) {
int ans = 0;
while (l[i] <= r[i]) ans += Query_Max(max(0LL, l[i] - t[i]), l[i]), ++l[i];
cout << ans << "\n";
}
return 0;
}
Compilation message (stderr)
ho_t5.cpp: In function 'int32_t main()':
ho_t5.cpp:79:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
for (int i = 0; i+(1<<lay-1) < n; ++i) {
~~~^~
ho_t5.cpp:80:75: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
st[lay][i] = max(st[lay - 1][i], st[lay - 1][i + (1 << lay-1)]);
~~~^~
ho_t5.cpp:85:17: warning: unused variable '_l' [-Wunused-variable]
int _l = max(0LL, l[i] - t[i]), _r = l[i];
^~
ho_t5.cpp:85:45: warning: unused variable '_r' [-Wunused-variable]
int _l = max(0LL, l[i] - t[i]), _r = l[i];
^~
ho_t5.cpp:51:35: warning: variable 'fl_sub4' set but not used [-Wunused-but-set-variable]
int fl_sub2 = 1, fl_sub3 = 1, fl_sub4 = 1;
^~~~~~~
# | 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... |