# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
475895 | Jarif_Rahman | Snowball (JOI21_ho_t2) | C++17 | 148 ms | 11600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e13;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q; cin >> n >> q;
vector<ll> v(n);
for(ll &x: v) cin >> x;
vector<ll> w(q);
for(ll &x: w) cin >> x;
vector<ll> sum(q+1);
sum[0] = 0;
for(int i = 0; i < q; i++) sum[i+1] = sum[i]+w[i];
vector<pair<ll, ll>> pos, neg;
pos.pb({0, 0});
neg.pb({0, 0});
ll a = 0, b = 0;
for(int i = 1; i <= q; i++){
if(sum[i] == 0) continue;
if(sum[i] > 0 && sum[i] > b){
b = sum[i];
pos.pb({b, -a});
}
if(sum[i] < 0 && sum[i] < a){
a = sum[i];
neg.pb({-a, b});
}
}
vector<ll> ans(n, 0);
for(int i = 0; i < n; i++){
if(i == 0){
ans[i]+=neg.back().f;
}
else{
int a = 0, b = neg.size(); b--;
while(a < b){
int md = (a+b+1)/2;
if(neg[md].f+neg[md].sc > v[i]-v[i-1]) b = md-1;
else a = md;
}
ll cur = neg[a].f;
if(a+1 != neg.size()) cur = max(cur, v[i]-v[i-1]-neg[a+1].sc);
ans[i]+=cur;
}
if(i == n-1){
ans[i]+=pos.back().f;
}
else{
int a = 0, b = pos.size(); b--;
while(a < b){
int md = (a+b+1)/2;
if(pos[md].f+pos[md].sc > v[i+1]-v[i]) b = md-1;
else a = md;
}
ll cur = pos[a].f;
if(a+1 != pos.size()) cur = max(cur, v[i+1]-v[i]-pos[a+1].sc);
ans[i]+=cur;
}
}
for(ll x: ans) cout << x << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |