#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int MXN = 200005;
int n, q, a[MXN], b[MXN], t[MXN], l[MXN], r[MXN], smg[MXN * 4];
void MONO(int w) {
deque<pii> dq;
for (int i = 0; i < n; i++) {
if (dq.size() && dq.front().second == i - w) dq.pop_front();
while (dq.size() && dq.back().first < a[i]) dq.pop_back();
dq.push_back({a[i], i});
b[i] = dq.front().first;
}
}
void build(int id, int l, int r) {
if (l + 1 == r) {
smg[id] = b[l];
return;
}
int mid = (l + r) >> 1;
build(id * 2 + 1, l, mid);
build(id * 2 + 2, mid, r);
smg[id] = smg[id * 2 + 1] + smg[id * 2 + 2];
}
int query(int id, int l, int r, int _l, int _r) {
if (_r <= l || r <= _l) return 0;
if (_l <= l && r <= _r) return smg[id];
int mid = (l + r) >> 1;
return query(id * 2 + 1, l, mid, _l, _r) + query(id * 2 + 2, mid, r, _l, _r);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < q; i++) cin >> t[i] >> l[i] >> r[i];
MONO(t[0] + 1);
build(0, 0, n);
for (int i = 0; i < n; i++) cout << query(0, 0, n, l[i] - 1, r[i]) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
140 ms |
14788 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
111 ms |
14100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
142 ms |
13748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |