이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second
#define pb push_back
#define rep(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define all(a) a.begin(),a.end()
#define sz(x) (ll)(x).size()
const int mxN = 2e5+7;
ll x[mxN],odp[mxN];
struct poz{
ll lewo,prawo;
ll suma;
int kogo_ruch; //0 brak, 1 lewo, 2 prawo
};
poz t[mxN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,q,w; cin >> n >> q;
rep(i,1,n) cin >> x[i];
ll akt=0,mL=0,mP=0;
rep(i,1,q){
cin >> w;
if(w > 0) t[i-1].kogo_ruch = 2;
if(w < 0) t[i-1].kogo_ruch = 1;
akt += w;
mL = min(akt,mL);
mP = max(akt,mP);
t[i] = {mL,mP,mP-mL,0};
}
odp[1] -= mL;
odp[n] += mP;
rep(i,2,n){
ll odl = x[i]-x[i-1];
int p=0,k=q;
while(p < k){
int m = (p+k+1)/2;
if(t[m].suma <= odl) p = m;
else k = m-1;
}
odp[i] -= t[p].lewo;
odp[i-1] += t[p].prawo;
odl -= t[p].prawo;
odl += t[p].lewo;
//cout << i << " " << odl << "\n";
if(t[p].kogo_ruch == 1) odp[i] += odl;
if(t[p].kogo_ruch == 2) odp[i-1] += odl;
}
//rep(i,0,q) cout << i << " " << t[i].lewo << " " << t[i].prawo << " " << t[i].suma << " " << t[i].kogo_ruch << "\n";
rep(i,1,n) cout << odp[i] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |