# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
602346 | CyberCow | Snowball (JOI21_ho_t2) | C++17 | 148 ms | 14012 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
using namespace std;
using ll = long long;
vector<ll> v;
vector<pair<ll, pair<ll, ll>>> p;
ll ans[200005];
void solve()
{
int n, i, j, q;
cin >> n >> q;
ll x, oo = 1000000000000000000LL;
v.push_back(-oo);
for ( i = 0; i < n; i++)
{
cin >> x;
v.push_back(x);
}
v.push_back(oo);
p.push_back({ 0,{ 0, 0 } });
ll tex = 0;
for ( i = 0; i < q; i++)
{
cin >> x;
tex += x;
pair<ll, pair<ll, ll>>anc = p.back();
anc.second.first = max(anc.second.first, tex);
anc.second.second = min(anc.second.second, tex);
anc.first = anc.second.first - anc.second.second;
p.push_back(anc);
}
sort(p.begin(), p.end());
int ind;
for (i = 1; i <= n; i++)
{
ind = lower_bound(p.begin(), p.end(), make_pair(v[i] - v[i - 1], make_pair(0LL, 0LL))) - p.begin();
if (ind == p.size())
ans[i] -= p[ind - 1].second.second;
else
{
if (p[ind].second.second != p[ind - 1].second.second)
ans[i] += v[i] - v[i - 1] - p[ind].second.first;
else
ans[i] += -p[ind].second.second;
}
ind = lower_bound(p.begin(), p.end(), make_pair(v[i + 1] - v[i], make_pair(0LL, 0LL))) - p.begin();
if (ind == p.size())
ans[i] += p[ind - 1].second.first;
else
{
if (p[ind].second.first != p[ind - 1].second.first)
ans[i] += v[i + 1] - v[i] - -p[ind].second.second;
else
ans[i] += p[ind].second.first;
}
}
for ( i = 1; i <= n; i++)
{
cout << ans[i] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |