이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define pb push_back
#define ins insert
#define fi first
#define se second
#define mpr make_pair
#define mxn (ll)(1e3 + 5)
ll n, m, l, x;
vector<ll> w, t, s;
vector<pii> v[mxn];
vector<pii> ran[mxn];
vector<ll> pref[mxn];
set<pair<pii, ll>> st;
int get(int pos)
{
return (*--st.upper_bound(mpr(mpr(pos, (ll)(2e18)), 0))).se;
}
void make(int l, int r, int val)
{
auto it = --st.upper_bound(mpr(mpr(l, (ll)(2e18)), 0));
pii tmp = (*it).fi;
ll vv = (*it).se;
if (tmp.se >= r)
{
st.erase(it);
ll l1 = tmp.fi;
ll r1 = l - 1;
ll l2 = r + 1;
ll r2 = tmp.se;
if (l1 <= r1) st.ins({{l1, r1}, vv});
if (l2 <= r2) st.ins({{l2, r2}, vv});
st.ins({{l, r}, val});
return;
}
if (tmp.se >= l)
{
st.erase(it);
int l1 = tmp.fi;
int r1 = l - 1;
if (l1 <= r1) st.ins({{l1, r1}, vv});
}
it = --st.upper_bound(mpr(mpr(r, (ll)(2e18)), 0));
tmp = (*it).fi;
vv = (*it).se;
if (tmp.se > r)
{
st.erase(it);
int l1 = r + 1;
int r1 = tmp.se;
if (l1 <= r1) st.ins({{l1, r1}, vv});
}
auto it1 = st.lower_bound(mpr(mpr(l, -(ll)(2e18)), 0));
auto it2 = st.upper_bound(mpr(mpr(r, (ll)(2e18)), 0));
st.erase(it1, it2);
st.ins({{l, r}, val});
}
void init(int L, int N, vector<ll> T, vector<int> W, int X, int M, vector<int> S)
{
n = N, m = M, l = L, x = X;
for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x);
for (ll i = 0; i < n; i++) v[0].pb({t[i], w[i]});
for (ll i = 0; i + 1 < m; i++)
{
sort(v[i].begin(), v[i].end(), [&](const pii &a, const pii &b)
{
if (a.fi == b.fi) return a.se < b.se;
return a.fi < b.fi;
});
for (ll j = 0; j < v[i].size(); j++)
{
if (!j || pref[i][j - 1] <= v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se)
{
v[i + 1].pb({v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se, v[i][j].se});
ran[i].pb({v[i][j].fi, v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se});
pref[i].pb(v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se);
continue;
}
v[i + 1].pb({pref[i][j - 1], v[i][j].se});
pref[i].pb(pref[i][j - 1]);
}
}
st.ins({{-1, (ll)(2e18)}, -1});
for (int i = m - 2; i >= 0; i--)
{
vector<pair<pii, ll>> late;
for (int j = 0; j < ran[i].size(); j++)
{
ll a = ran[i][j].fi;
ll c = ran[i][j].se;
ll b = (j + 1 < ran[i].size() ? ran[i][j + 1].fi : (ll)(2e18));
ll lb = a + 1;
ll ub = min(c - (s[i + 1] - s[i]) * x, b);
if (lb > ub) continue;
if (i == m - 2) late.pb({{lb, ub}, c});
else
{
ll upd = get(c);
if (upd == -1) upd = c + (m - i - 2) * x;
late.pb({{lb, ub}, upd});
}
}
for (const pair<pii, ll> &p : late)
{
make(p.fi.fi, p.fi.se, p.se);
}
}
}
ll arrival_time(ll Y)
{
ll cur = get(Y);
if (cur == -1) return l * x;
return cur;
}
컴파일 시 표준 에러 (stderr) 메시지
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:70:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
70 | for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x);
| ^~~
overtaking.cpp:70:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
70 | for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x);
| ^~~
overtaking.cpp:79:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (ll j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
overtaking.cpp:96:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for (int j = 0; j < ran[i].size(); j++)
| ~~^~~~~~~~~~~~~~~
overtaking.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | ll b = (j + 1 < ran[i].size() ? ran[i][j + 1].fi : (ll)(2e18));
| ~~~~~~^~~~~~~~~~~~~~~| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |