제출 #733565

#제출 시각아이디문제언어결과실행 시간메모리
733565PringFire (JOI20_ho_t5)C++14
0 / 100
141 ms14792 KiB
#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]); build(0, 0, n); for (int i = 0; i < n; i++) cout << query(0, 0, n, l[i] - 1, r[i]) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...