# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
624324 |
2022-08-07T19:48:03 Z |
Ronin13 |
Snowball (JOI21_ho_t2) |
C++14 |
|
0 ms |
0 KB |
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int NMAX = 200005;
const ll linf = 5e18 + 1;
ll mn[NMAX], mx[NMAX];
int main(){
int n, q; cin >> n >> q;
ll a[n + 2];
a[0] = -linff;
a[n + 1] = linf;
for(int i =1; i <= n; i++) cin >> a[i];
ll pref[q + 1];
mn[0] = 0;
mx[0] = 0;
pref[0] = 0;
for(int i = 1; i <= q; i++){
ll x; cin >> x;
pref[i] = pref[i - 1] + x;
mx[i] = max(mx[i - 1], pref[i]);
mn[i] = min(mn[i - 1], pref[i]);
//cout << mx[i] << ' ' << mn[i] << "\n";
}
ll ans[n + 2];
for(int i = 0; i <= n + 1; i++) ans[i] = 0;
for(int i = 1; i <= n + 1; i++){
ll l = 0, r = a[i] - a[i - 1] + 1;
while(l + 1 < r){
ll mid = (l + r) / 2;
ll l1 = -1, r1 = q + 1;
while(l1 + 1 < r1){
ll mid1 = l1 + r1; mid1 /= 2;
if(mn[mid1] <= -mid) r1 = mid1;
else l1 = mid1;
}
// cout << 1;
if(r1 == q + 1){
r = mid;
continue;
}
if(mx[r1] <= a[i] - a[i - 1] - mid) l = mid;
else {r = mid;}
}
//cout << l << "\n";
ans[i - 1] += min(mx[q], a[i] - a[i - 1] - l);
ans[i] += l;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << "\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:20:13: error: 'linff' was not declared in this scope; did you mean 'linf'?
20 | a[0] = -linff;
| ^~~~~
| linf