이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> lp, rp, wl, wr;
ll p, re = (1LL << 50);
void update(bool w, ll i, ll x)
{
while (i > 0)
{
if (w)
rp[i] = min(rp[i], x);
else
lp[i] = min(lp[i], x);
i /= 2;
}
return;
}
ll qmin(bool w, ll l, ll r, ll i)
{
if (wl[i] >= r || wr[i] <= l)
return re;
if (wl[i] >= l && wr[i] <= r)
{
if (w)
return rp[i];
else
return lp[i];
}
return min(qmin(w, l, r, 2 * i), qmin(w, l, r, 2 * i + 1));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll m, n, i, j, k, a, b, w = 0, ma;
cin >> m >> n;
vector<vector<ll> > v, vv(m);
vector<ll> d(m), s(3 * m);
for (i = 0; i < m; i++)
{
cin >> j;
v.push_back({j - 1, i, -1});
cin >> j;
v.push_back({j - 1, i, 1});
cin >> j;
v.push_back({j - 1, i, 0});
cin >> d[i];
}
sort(v.begin(), v.end());
if (v[0][0] || v[3 * m - 1][0] != n - 1)
{
cout << -1;
return 0;
}
for (i = 0; i < 3 * m; i++)
{
if (!i)
s[i] = 0;
else if (v[i][0] > v[i - 1][0])
s[i] = s[i - 1] + 1;
else
s[i] = s[i - 1];
w = max(w, s[i]);
}
for (i = 0; i < 3 * m; i++)
v[i] = {v[i][1], s[i], v[i][2]};
sort(v.begin(), v.end());
for (i = 0; i < m; i++)
vv[i] = {v[3 * i][1], v[3 * i + 1][1], v[3 * i + 2][1]};
p = w + 1;
while (p != (p & -p))
p++;
lp.resize(2 * p);
rp.resize(2 * p);
wl.resize(2 * p);
wr.resize(2 * p);
for (i = p; i < 2 * p; i++)
{
lp[i] = rp[i] = re;
wl[i] = i;
wr[i] = i + 1;
}
lp[p] = rp[p + w] = 0;
for (i = p - 1; i > 0; i--)
{
lp[i] = min(lp[2 * i], lp[2 * i + 1]);
rp[i] = min(rp[2 * i], rp[2 * i + 1]);
wl[i] = wl[2 * i];
wr[i] = wr[2 * i + 1];
}
ma = re;
ll ml, mr;
for (i = 0; i < m; i++)
{
update(0, vv[i][1] + p, qmin(0, vv[i][0] + p, vv[i][1] + p, 1) + d[i]);
update(1, vv[i][1] + p, qmin(1, vv[i][1] + 1 + p, vv[i][2] + 1 + p, 1) + d[i]);
ma = min(ma, qmin(0, vv[i][0] + p, w + 1 + p, 1) + qmin(1, p, vv[i][2] + 1 + p, 1) + d[i]);
}
for (j = 1; j <= w; j++)
rp[j] = min(rp[j + p], rp[j + p - 1]);
for (j = w - 1; j >= 0; j--)
lp[j + p] = min(lp[j + p], lp[j + p + 1]);
for (j = 0; j <= w; j++)
ma = min(ma, lp[j + p] + rp[j + p]);
if (ma < re)
cout << ma;
else
cout << -1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
pinball.cpp: In function 'int main()':
pinball.cpp:35:20: warning: unused variable 'k' [-Wunused-variable]
35 | ll m, n, i, j, k, a, b, w = 0, ma;
| ^
pinball.cpp:35:23: warning: unused variable 'a' [-Wunused-variable]
35 | ll m, n, i, j, k, a, b, w = 0, ma;
| ^
pinball.cpp:35:26: warning: unused variable 'b' [-Wunused-variable]
35 | ll m, n, i, j, k, a, b, w = 0, ma;
| ^
pinball.cpp:92:8: warning: unused variable 'ml' [-Wunused-variable]
92 | ll ml, mr;
| ^~
pinball.cpp:92:12: warning: unused variable 'mr' [-Wunused-variable]
92 | ll ml, mr;
| ^~
# | 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... |