Task: | Kyselyt |
Sender: | ollpu |
Submission time: | 2020-10-16 19:55:00 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 34 |
#3 | ACCEPTED | 54 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.15 s | 2, 3 | details |
#3 | ACCEPTED | 0.16 s | 3 | details |
#4 | ACCEPTED | 0.22 s | 3 | details |
#5 | ACCEPTED | 0.15 s | 3 | details |
Code
#include <bits/stdc++.h>using namespace std;const int N = 1<<18;long sp[2*N];void sp_set(int x, long v) {x += N;sp[x] = v;while (x /= 2) {sp[x] = sp[2*x]+sp[2*x+1];}}long sp_get(int a, int b) {long res = 0;for (a += N, b += N; a <= b; a /= 2, b /= 2) {if (a&1) res += sp[a++];if (~b&1) res += sp[b--];}return res;}int main() {ios::sync_with_stdio(0);cin.tie(0);int n, q;cin >> n >> q;int t[n];for (int i = 0; i < n; ++i) cin >> t[i];long st[n+1];st[0] = 0;for (int i = 0; i < n; ++i) {st[i+1] = st[i] + t[i];}vector<pair<int, int>> qat[n];long ans[q];for (int i = 0; i < q; ++i) {int a, b;cin >> a >> b;a--; b--;qat[a].emplace_back(b, i);ans[i] = -(st[b+1]-st[a]);}vector<pair<int, int>> p;p.emplace_back(n, 2e9);for (int i = n-1; i >= 0; --i) {while (p.back().second <= t[i]) {p.pop_back();}long bcst = long(p.back().first-i)*t[i];sp_set(p.size(), bcst);p.emplace_back(i, t[i]);for (auto [b, j] : qat[i]) {int x = lower_bound(p.begin(), p.end(), b, [](auto pr, int u) {return pr.first > u;})-p.begin();ans[j] += sp_get(x+1, p.size()-1);ans[j] += long(b-p[x].first+1)*p[x].second;}}for (int i = 0; i < q; ++i) cout << ans[i] << "\n";}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 100 70 8 72 88 42 78 85 41 23 36 6... |
correct output |
---|
99 0 922 2579 1892 ... |
user output |
---|
99 0 922 2579 1892 ... Truncated |
Test 2
Group: 2, 3
Verdict: ACCEPTED
input |
---|
200000 200000 98 99 29 92 29 81 100 52 89 80... |
correct output |
---|
1497732 2810356 9532632 6655773 5403513 ... |
user output |
---|
1497732 2810356 9532632 6655773 5403513 ... Truncated |
Test 3
Group: 3
Verdict: ACCEPTED
input |
---|
200000 200000 818377786 934884634 816080381 ... |
correct output |
---|
86877225712611 94684086875470 92703793485296 38149694892093 61948503092286 ... |
user output |
---|
86877225712611 94684086875470 92703793485296 38149694892093 61948503092286 ... Truncated |
Test 4
Group: 3
Verdict: ACCEPTED
input |
---|
200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
0 0 0 0 0 ... |
user output |
---|
0 0 0 0 0 ... Truncated |
Test 5
Group: 3
Verdict: ACCEPTED
input |
---|
200000 200000 200000 199999 199998 199997 19... |
correct output |
---|
15920862903 3193483321 18874982071 4846348926 3970697055 ... |
user output |
---|
15920862903 3193483321 18874982071 4846348926 3970697055 ... Truncated |