# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
699070 |
2023-02-15T14:23:54 Z |
jiahng |
Snowball (JOI21_ho_t2) |
C++14 |
|
5 ms |
476 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair <pi,pi> pipi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 1000010
#define INF (ll)1e18
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
#define DEBUG 0
#pragma GCC optimize("trapv")
int N,Q,w;
int pref[maxn],mnpref[maxn];
int L[maxn],R[maxn],X[maxn];
int32_t main(){
cin >> N >> Q;
FOR(i,1,N) cin >> X[i];
int mxpref=0;
FOR(i,1,Q){
cin >> w;
pref[i] = pref[i-1] + w;
mnpref[i] = min(pref[i], mnpref[i-1]);
mxpref = max(mxpref, pref[i]);
}
vpi v;
FOR(i,1,Q) v.pb(pi(mnpref[i], pref[i]));
sort(all(v));
DEC(i,v.size()-2,0) v[i].s = max(v[i].s,v[i+1].s);
L[1] = X[1] + mnpref[Q];
R[N] = X[N] + mxpref-1;
FOR(i,1,N-1){
int l = X[i], r = mxpref+X[i]+1;
while (l+1<r){
int m = (l + r) >> 1;
auto it = upper_bound(all(v), pi(m - X[i+1], INF));
if (it != v.end() && it->s > m - X[i]) l = m;
else r = m;
}
R[i] = l; L[i+1] = max(l+1,X[i+1]+mnpref[Q]);
}
FOR(i,1,N) cout << R[i] - L[i] + 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
476 KB |
Output is correct |
7 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
476 KB |
Output is correct |
7 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |