이 제출은 이전 버전의 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;
ll get(ll pos)
{
return (*--st.upper_bound(mpr(mpr(pos, (ll)(2e18)), 0))).se;
}
void make(ll l, ll r, ll val)
{
// cout << l << ' ' << r << ' ' << val << '\n';
auto it = --st.lower_bound(mpr(mpr(l, -(ll)(2e18)), -(ll)(2e18)));
pii tmp = (*it).fi;
ll vv = (*it).se;
if (tmp.se >= l)
{
st.erase(it);
ll l1 = tmp.fi;
ll r1 = l - 1;
if (l1 <= r1) st.ins({{l1, r1}, vv});
if (l <= tmp.se) st.ins({{l, tmp.se}, vv});
}
it = --st.upper_bound(mpr(mpr(r, (ll)(2e18)), (ll)(2e18)));
tmp = (*it).fi;
vv = (*it).se;
if (tmp.se > r)
{
st.erase(it);
ll l1 = r + 1;
ll r1 = tmp.se;
if (l1 <= r1) st.ins({{l1, r1}, vv});
if (tmp.fi <= r) st.ins({{tmp.fi, r}, vv});
}
auto it1 = st.lower_bound(mpr(mpr(l, -(ll)(2e18)), -(ll)(2e18)));
auto it2 = st.upper_bound(mpr(mpr(r, (ll)(2e18)), (ll)(2e18)));
st.erase(it1, it2);
st.ins({{l, r}, val});
// for (pair<pii, ll> asd : st) cout << asd.fi.fi << ' ' << asd.fi.se << ' ' << asd.se << " | ";
// cout << '\n';
}
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({{0, (ll)(2e18)}, -1});
for (ll i = m - 2; i >= 0; i--)
{
vector<pair<pii, ll>> late;
for (ll 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 + (s[m - 1] - s[i]) * x;
ll ub = min(c - (s[i + 1] - s[i]) * x, b) + (s[m - 1] - s[i]) * x;
if (lb > ub) continue;
ll upd = get(c + (s[m - 1] - s[i + 1]) * x);
if (upd == -1) upd = c + (s[m - 1] - s[i + 1]) * x;
late.pb({{lb, ub}, upd});
}
for (const pair<pii, ll> &p : late)
{
make(p.fi.fi, p.fi.se, p.se);
}
}
// for (pair<pii, ll> x : st) cout << x.fi.fi << ' ' << x.fi.se << ' ' << x.se << " | ";
// cout << '\n';
}
ll arrival_time(ll Y)
{
Y += l * x;
ll cur = get(Y);
return (cur == -1 ? Y : 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:63:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
63 | for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x);
| ^~~
overtaking.cpp:63:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
63 | for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x);
| ^~~
overtaking.cpp:72: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]
72 | for (ll j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
overtaking.cpp:89: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]
89 | for (ll j = 0; j < ran[i].size(); j++)
| ~~^~~~~~~~~~~~~~~
overtaking.cpp:93:27: 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]
93 | 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... |