Submission #412981

#TimeUsernameProblemLanguageResultExecution timeMemory
412981OzySnowball (JOI21_ho_t2)C++17
33 / 100
2573 ms2368 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debugsl(a) cout << #a << " = " << a << ", " #define debug(a) cout << #a << " = " << a << endl #define MAX 200000 #define pos first #define l second.first #define r second.second pair<lli, pair<lli,lli> > arr[MAX+2]; lli n,q,a; lli res[MAX+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; a = 1ll<<62; arr[0].l = -a; arr[0].r = -a; arr[n+1].l = a; arr[n+1].r = a; rep(i,1,n) { cin >> a; arr[i].l = a; arr[i].r = a; arr[i].pos = a; } rep(x,1,q) { cin >> a; rep(i,1,n) { if (a < 0) { if ((arr[i-1].r < arr[i].l) && arr[i].pos+a < arr[i].l) { res[i] += arr[i].l - max((arr[i-1].r), arr[i].pos+a); } arr[i].pos += a; arr[i].l = min(arr[i].l, arr[i].pos); } else if (a > 0) { if ((arr[i+1].l > arr[i].r) && arr[i].pos+a > arr[i].r) { res[i] += min(arr[i+1].l, arr[i].pos+a) - arr[i].r; } arr[i].pos += a; arr[i].r = max(arr[i].pos, arr[i].r); } } } rep(i,1,n) cout << res[i] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...