Submission #699074

#TimeUsernameProblemLanguageResultExecution timeMemory
699074jiahngSnowball (JOI21_ho_t2)C++14
100 / 100
677 ms18608 KiB
#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]-1, r = X[i+1] + 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...