# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
435816 | tutis | Distributing Candies (IOI21_candies) | C++17 | 128 ms | 7352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
vector<int> s(n, 0);
int q = l.size();
vector<pair<ll, ll>>D = {{0ll, (ll)1e16 + 1}};
for (int i = 0; i < q; i++)
{
while (v[i] != 0)
{
if (v[i] > 0)
{
ll x = D.back().second - D.back().first;
if (v[i] >= x)
{
v[i] -= x;
D.pop_back();
}
else
{
D.back().first += v[i];
v[i] = 0;
}
}
else
{
if (D.back().first != 0)
{
if (-v[i] >= D.back().first)
{
v[i] += D.back().first;
D.back().first = 0;
}
else
{
D.push_back({0, -v[i]});
v[i] = 0;
}
}
else
{
if (D.size() == 1)
v[i] = 0;
else
{
ll x = D[D.size() - 2].first - D.back().second;
if (-v[i] >= x)
{
v[i] += x;
D.pop_back();
D.back().first = 0;
}
else
{
D.back().second += -v[i];
v[i] = 0;
}
}
}
}
}
}
reverse(D.begin(), D.end());
vector<ll>S(D.size());
S[0] = D[0].first;
for (int i = 1; i < D.size(); i++)
S[i] = S[i - 1] + D[i].first - D[i - 1].second;
for (int j = 0; j < n; j++)
{
if (c[j] <= D[0].first)
s[j] = c[j];
else
{
int lo = 0;
int hi = D.size() - 1;
while (lo <= hi)
{
int i = (lo + hi) / 2;
if (D[i].first <= c[j] && c[j] <= D[i].second)
{
s[j] = S[i];
break;
}
if (c[j] <= D[i].first)
hi = i - 1;
else
{
if (c[j] <= D[i + 1].first)
{
s[j] = S[i] + (c[j] - D[i].second);
break;
}
lo = i + 1;
}
}
}
}
return s;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |