Task: | Kyselyt |
Sender: | ArktinenKarpalo |
Submission time: | 2020-10-16 22:59:39 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 46 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 34 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.22 s | 2, 3 | details |
#3 | WRONG ANSWER | 0.28 s | 3 | details |
#4 | ACCEPTED | 0.40 s | 3 | details |
#5 | ACCEPTED | 0.25 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:69:10: warning: unused variable 'lb' [-Wunused-variable] int lb =bi.first; // INCLUSIVE BOTH ^~
Code
#include <bits/stdc++.h> #define ll long long #define ld long double #define M 1000000007 using namespace std; ll x[202020]; ll ans[202020], xs[202020]; vector<pair<int,int>> bq[202020]; // X, Korkeus, Summa, pituus(helppouden takia) set<tuple<ll, ll, ll, ll>> st; ll ts(int a, int b) { return xs[b]-xs[a-1]; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(); int n, q; cin >> n >> q; for(int i=0; i<n; i++) { cin >> x[i]; xs[i] = xs[i-1]+x[i]; } for(int i=0; i<q; i++) { int a, b; cin >> a >> b; b--; a--; bq[a].push_back(make_pair(b, i)); } ll sum = 0; ll ht = 0; for(int i=n-1; i>=0; i--) { // updt set ht = x[i]; auto u = make_tuple(i,ht,0,1); if(!st.empty()) get<2>(u) = get<2>(*st.begin()); while(st.begin() != st.end() && get<1>(*st.begin()) <= ht) { sum += get<3>(*st.begin())*(ht-get<1>(*st.begin())); get<2>(u) += get<3>(*st.begin())*(ht-get<1>(*st.begin())); get<3>(u) += get<3>(*st.begin()); st.erase(st.begin()); } st.insert(u); // handle bq for(auto bi:bq[i]) { ll bans = sum; auto it = st.upper_bound({bi.first,0,0,0}); if(it != st.end()) { bans -= get<2>(*it); } if(it != st.begin()) { it--; auto ed = *it; if(get<0>(ed)+get<3>(ed)-1 > bi.first) { int lb =bi.first; // INCLUSIVE BOTH int rb = get<0>(ed)+get<3>(ed)-1; bans -= (rb-bi.first)*get<1>(ed)-ts(bi.first+1, rb); } } ans[bi.second] = bans; } } 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: WRONG ANSWER
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 |