This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 200010;
int n, q;
int pos[MAX];
int dx[MAX];
int ev[MAX], evs;
int pref[MAX], lpref[MAX], rpref[MAX];
int res[MAX];
int search(int len){
int L = 1, R = evs, mid;
while(L < R){
mid = (L + R) / 2;
if(pref[mid] > len) R = mid;
else L = mid + 1;
}
return L;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
FOR(i, 1, n, 1){
cin>>pos[i];
}
pos[0] = -LNF;
pos[n+1] = LNF;
int L = 0, R = 0, now = 0;
FOR(i, 1, q, 1){
cin>>dx[i];
now += dx[i];
if(now < L){
evs++;
ev[evs] = now - L;
L = now;
}
if(R < now){
evs++;
ev[evs] = now - R;
R = now;
}
}
FOR(i, 1, evs, 1){
lpref[i] = lpref[i-1];
rpref[i] = rpref[i-1];
if(ev[i] > 0){
// [--->......]
lpref[i] += ev[i];
}
else{
// [......<---]
rpref[i] += (-ev[i]);
}
pref[i] = lpref[i] + rpref[i];
}
FOR(i, 0, n, 1){
int len = pos[i+1] - pos[i];
if(len >= pref[evs]){
res[i] += lpref[evs];
res[i+1] += rpref[evs];
}
else{
int ptr = search(len);
res[i] += lpref[ptr - 1];
res[i+1] += rpref[ptr - 1];
if(ev[ptr] > 0) res[i] += len - pref[ptr - 1];
else res[i+1] += len - pref[ptr - 1];
}
}
FOR(i, 1, n, 1){
cout<<res[i]<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |