#include "nile.h"
#include<bits/stdc++.h>
using namespace std;
vector<long long> big0(500001,-1e18);
vector<long long> big1(500001,-1e18);
vector<long long> seg0(500001,-1e18);
vector<long long> seg1(500001,-1e18);
vector<long long> haha(500001);
vector<long long> pr(500001);
long long n;
void build(long long l, long long r, long long x) {
if(l == r) {
if(l%2) {
big1[x] = haha[l];
}
else {
big0[x] = haha[l];
}
return;
}
long long mid = (l+r)/2;
build(l,mid,x*2);
build(mid+1,r,x*2+1);
big0[x] = max(big0[x*2],big0[x*2+1]);
big1[x] = max(big1[x*2],big1[x*2+1]);
}
void upd(long long l, long long r, long long x, long long p, long long br) {
if(l == r) {
if(l%2) {
seg1[x] = br;
}
else {
seg0[x] = br;
}
return;
}
long long mid = (l+r)/2;
if(p <= mid) {
upd(l,mid,x*2,p,br);
}
else {
upd(mid+1,r,x*2+1,p,br);
}
seg0[x] = max(seg0[x*2],seg0[x*2+1]);
seg1[x] = max(seg1[x*2],seg1[x*2+1]);
}
long long calc(long long l, long long r, long long ql, long long qr, long long x, bool y, bool z) {
if(qr < ql) {
return -1e18;
}
if(l == ql && r == qr) {
if(y) {
if(z) {
return big1[x];
}
else {
return big0[x];
}
}
else {
if(z) {
return seg1[x];
}
else {
return seg0[x];
}
}
}
long long mid = (l+r)/2;
if(qr <= mid) {
return calc(l,mid,ql,qr,x*2,y,z);
}
else if(ql > mid) {
return calc(mid+1,r,ql,qr,x*2+1,y,z);
}
else {
return max(calc(l,mid,ql,mid,x*2,y,z),calc(mid+1,r,mid+1,qr,x*2+1,y,z));
}
}
long long dude(long long l, long long r) {
if(r < l) {
return 0;
}
long long ans = pr[r]-pr[l-1];
long long c = max(calc(1,n,l,r,1,1,l%2),calc(1,n,l,r,1,0,(l+1)%2));
if((r-l+1)%2 == 0) {
c = 0;
}
return ans-c;
}
std::vector<long long> calculate_costs(std::vector<int> w, std::vector<int> a, std::vector<int> b, std::vector<int> e) {
vector<pair<long long,long long>> wut(1,{0,0});
n = w.size();
for(long long i = 0; i < w.size(); i++) {
wut.push_back({w[i],i});
}
sort(wut.begin(),wut.end());
for(long long i = 1; i <= n; i++) {
haha[i] = b[wut[i].second]-a[wut[i].second];
pr[i] = b[wut[i].second]+pr[i-1];
}
build(1,n,1);
vector<long long> ans(e.size());
vector<pair<long long,long long>> no(0);
for(long long i = 0; i < e.size(); i++) {
no.push_back({e[i],i});
}
sort(no.begin(),no.end());
long long sb = 0;
for(long long i = 0; i < a.size(); i++) {
sb+=a[i];
}
vector<pair<long long,pair<long long,long long>>> wow(0);
for(long long i = 2; i <= n; i++) {
wow.push_back({wut[i].first-wut[i-1].first,{0,i-1}});
if(i > 2) {
wow.push_back({wut[i].first-wut[i-2].first,{1,i-2}});
}
}
upd(1,n,1,1,haha[1]);
upd(1,n,1,n,haha[n]);
sort(wow.begin(),wow.end());
set<long long> idk;
for(long long i = 0; i <= w.size(); i++) {
idk.insert(i);
}
long long y = 0;
for(long long i = 0; i < wow.size(); i++) {
while(y < no.size() && no[y].first < wow[i].first) {
ans[no[y].second] = sb;
y++;
}
long long p = wow[i].second.second;
if(wow[i].second.first) {
p++;
long long l = *(--idk.upper_bound(p)),r = *idk.lower_bound(p);
sb-=dude(l+1,r);
upd(1,n,1,p,b[wut[p].second]-a[wut[p].second]);
sb+=dude(l+1,r);
}
else {
idk.erase(p);
long long l = *(--idk.upper_bound(p)),r = *idk.lower_bound(p);
sb-=dude(l+1,p);
sb-=dude(p+1,r);
sb+=dude(l+1,r);
}
}
for(long long i = y; i < no.size(); i++) {
ans[no[i].second] = sb;
}
return ans;
}
Compilation message
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:101:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(long long i = 0; i < w.size(); i++) {
| ~~^~~~~~~~~~
nile.cpp:112:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(long long i = 0; i < e.size(); i++) {
| ~~^~~~~~~~~~
nile.cpp:117:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(long long i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
nile.cpp:131:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for(long long i = 0; i <= w.size(); i++) {
| ~~^~~~~~~~~~~
nile.cpp:135:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(long long i = 0; i < wow.size(); i++) {
| ~~^~~~~~~~~~~~
nile.cpp:136:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | while(y < no.size() && no[y].first < wow[i].first) {
| ~~^~~~~~~~~~~
nile.cpp:156:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
156 | for(long long i = y; i < no.size(); i++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24156 KB |
Output is correct |
2 |
Correct |
11 ms |
24156 KB |
Output is correct |
3 |
Correct |
10 ms |
24104 KB |
Output is correct |
4 |
Correct |
11 ms |
24152 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
15 ms |
24156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
36992 KB |
Output is correct |
2 |
Correct |
145 ms |
38664 KB |
Output is correct |
3 |
Correct |
143 ms |
38620 KB |
Output is correct |
4 |
Correct |
168 ms |
38652 KB |
Output is correct |
5 |
Correct |
144 ms |
38692 KB |
Output is correct |
6 |
Correct |
132 ms |
38580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
37224 KB |
Output is correct |
2 |
Correct |
208 ms |
37052 KB |
Output is correct |
3 |
Correct |
217 ms |
37200 KB |
Output is correct |
4 |
Correct |
218 ms |
37192 KB |
Output is correct |
5 |
Correct |
159 ms |
37052 KB |
Output is correct |
6 |
Correct |
205 ms |
37056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24156 KB |
Output is correct |
2 |
Correct |
11 ms |
24156 KB |
Output is correct |
3 |
Correct |
10 ms |
24104 KB |
Output is correct |
4 |
Correct |
11 ms |
24152 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
15 ms |
24156 KB |
Output is correct |
7 |
Correct |
11 ms |
24152 KB |
Output is correct |
8 |
Correct |
11 ms |
24236 KB |
Output is correct |
9 |
Correct |
12 ms |
24152 KB |
Output is correct |
10 |
Correct |
12 ms |
24156 KB |
Output is correct |
11 |
Correct |
11 ms |
24528 KB |
Output is correct |
12 |
Correct |
11 ms |
24156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24156 KB |
Output is correct |
2 |
Correct |
11 ms |
24156 KB |
Output is correct |
3 |
Correct |
10 ms |
24104 KB |
Output is correct |
4 |
Correct |
11 ms |
24152 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
15 ms |
24156 KB |
Output is correct |
7 |
Correct |
139 ms |
36992 KB |
Output is correct |
8 |
Correct |
145 ms |
38664 KB |
Output is correct |
9 |
Correct |
143 ms |
38620 KB |
Output is correct |
10 |
Correct |
168 ms |
38652 KB |
Output is correct |
11 |
Correct |
144 ms |
38692 KB |
Output is correct |
12 |
Correct |
132 ms |
38580 KB |
Output is correct |
13 |
Correct |
177 ms |
37224 KB |
Output is correct |
14 |
Correct |
208 ms |
37052 KB |
Output is correct |
15 |
Correct |
217 ms |
37200 KB |
Output is correct |
16 |
Correct |
218 ms |
37192 KB |
Output is correct |
17 |
Correct |
159 ms |
37052 KB |
Output is correct |
18 |
Correct |
205 ms |
37056 KB |
Output is correct |
19 |
Correct |
11 ms |
24152 KB |
Output is correct |
20 |
Correct |
11 ms |
24236 KB |
Output is correct |
21 |
Correct |
12 ms |
24152 KB |
Output is correct |
22 |
Correct |
12 ms |
24156 KB |
Output is correct |
23 |
Correct |
11 ms |
24528 KB |
Output is correct |
24 |
Correct |
11 ms |
24156 KB |
Output is correct |
25 |
Correct |
169 ms |
38580 KB |
Output is correct |
26 |
Correct |
185 ms |
38876 KB |
Output is correct |
27 |
Correct |
218 ms |
38844 KB |
Output is correct |
28 |
Correct |
221 ms |
38836 KB |
Output is correct |
29 |
Correct |
163 ms |
38768 KB |
Output is correct |
30 |
Correct |
211 ms |
39020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
37224 KB |
Output is correct |
2 |
Correct |
208 ms |
37052 KB |
Output is correct |
3 |
Correct |
217 ms |
37200 KB |
Output is correct |
4 |
Correct |
218 ms |
37192 KB |
Output is correct |
5 |
Correct |
159 ms |
37052 KB |
Output is correct |
6 |
Correct |
205 ms |
37056 KB |
Output is correct |
7 |
Correct |
191 ms |
40300 KB |
Output is correct |
8 |
Correct |
218 ms |
40248 KB |
Output is correct |
9 |
Correct |
257 ms |
40244 KB |
Output is correct |
10 |
Correct |
251 ms |
40240 KB |
Output is correct |
11 |
Correct |
263 ms |
40312 KB |
Output is correct |
12 |
Correct |
264 ms |
40244 KB |
Output is correct |
13 |
Correct |
237 ms |
40248 KB |
Output is correct |
14 |
Correct |
191 ms |
40244 KB |
Output is correct |
15 |
Correct |
249 ms |
40136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24156 KB |
Output is correct |
3 |
Correct |
11 ms |
24156 KB |
Output is correct |
4 |
Correct |
10 ms |
24104 KB |
Output is correct |
5 |
Correct |
11 ms |
24152 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
15 ms |
24156 KB |
Output is correct |
8 |
Correct |
139 ms |
36992 KB |
Output is correct |
9 |
Correct |
145 ms |
38664 KB |
Output is correct |
10 |
Correct |
143 ms |
38620 KB |
Output is correct |
11 |
Correct |
168 ms |
38652 KB |
Output is correct |
12 |
Correct |
144 ms |
38692 KB |
Output is correct |
13 |
Correct |
132 ms |
38580 KB |
Output is correct |
14 |
Correct |
177 ms |
37224 KB |
Output is correct |
15 |
Correct |
208 ms |
37052 KB |
Output is correct |
16 |
Correct |
217 ms |
37200 KB |
Output is correct |
17 |
Correct |
218 ms |
37192 KB |
Output is correct |
18 |
Correct |
159 ms |
37052 KB |
Output is correct |
19 |
Correct |
205 ms |
37056 KB |
Output is correct |
20 |
Correct |
11 ms |
24152 KB |
Output is correct |
21 |
Correct |
11 ms |
24236 KB |
Output is correct |
22 |
Correct |
12 ms |
24152 KB |
Output is correct |
23 |
Correct |
12 ms |
24156 KB |
Output is correct |
24 |
Correct |
11 ms |
24528 KB |
Output is correct |
25 |
Correct |
11 ms |
24156 KB |
Output is correct |
26 |
Correct |
169 ms |
38580 KB |
Output is correct |
27 |
Correct |
185 ms |
38876 KB |
Output is correct |
28 |
Correct |
218 ms |
38844 KB |
Output is correct |
29 |
Correct |
221 ms |
38836 KB |
Output is correct |
30 |
Correct |
163 ms |
38768 KB |
Output is correct |
31 |
Correct |
211 ms |
39020 KB |
Output is correct |
32 |
Correct |
191 ms |
40300 KB |
Output is correct |
33 |
Correct |
218 ms |
40248 KB |
Output is correct |
34 |
Correct |
257 ms |
40244 KB |
Output is correct |
35 |
Correct |
251 ms |
40240 KB |
Output is correct |
36 |
Correct |
263 ms |
40312 KB |
Output is correct |
37 |
Correct |
264 ms |
40244 KB |
Output is correct |
38 |
Correct |
237 ms |
40248 KB |
Output is correct |
39 |
Correct |
191 ms |
40244 KB |
Output is correct |
40 |
Correct |
249 ms |
40136 KB |
Output is correct |
41 |
Correct |
200 ms |
42044 KB |
Output is correct |
42 |
Correct |
230 ms |
42176 KB |
Output is correct |
43 |
Correct |
257 ms |
42296 KB |
Output is correct |
44 |
Correct |
240 ms |
42240 KB |
Output is correct |
45 |
Correct |
246 ms |
42280 KB |
Output is correct |
46 |
Correct |
253 ms |
42544 KB |
Output is correct |
47 |
Correct |
247 ms |
42288 KB |
Output is correct |
48 |
Correct |
189 ms |
41992 KB |
Output is correct |
49 |
Correct |
249 ms |
42296 KB |
Output is correct |