이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m, n;
int A[100005], B[100005], C[100005], D[100005];
ll inf = 0x3f3f3f3f3f3f3f3f;
vector<int> xidx;
int sz;
struct SGT {
ll tree[300005 << 2];
SGT() {
memset(tree, 0x3f, sizeof(tree));
}
void update(int idx, ll val) {
idx += sz;
tree[idx] = val;
idx /= 2;
while (idx) {
tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);
idx /= 2;
}
}
ll query(int le, int ri) {
le += sz;
ri += sz;
ll ret = inf;
while (le <= ri) {
if (le & 1)ret = min(ret, tree[le++]);
if (!(ri & 1))ret = min(ret, tree[ri--]);
le /= 2;
ri /= 2;
}
return ret;
}
};
int get_idx(int x) {
return lower_bound(xidx.begin(), xidx.end(), x) - xidx.begin();
}
SGT lsgt, rsgt;
int main() {
scanf("%d%d", &m, &n);
xidx.push_back(1);
xidx.push_back(n);
for (int i = 0; i < m; i++) {
scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
xidx.push_back(A[i]);
xidx.push_back(B[i]);
xidx.push_back(C[i]);
}
sort(xidx.begin(), xidx.end());
xidx.erase(unique(xidx.begin(), xidx.end()), xidx.end());
sz = 1;
while (sz < xidx.size())sz *= 2;
lsgt.update(0, 0);
rsgt.update(xidx.size() - 1, 0);
ll ans = inf;
for (int i = 0; i < m; i++) {
ll le = lsgt.query(get_idx(A[i]), get_idx(B[i]));
lsgt.update(get_idx(C[i]), le+D[i]);
ll ri = rsgt.query(get_idx(A[i]), get_idx(B[i]));
rsgt.update(get_idx(C[i]), ri+D[i]);
ans = min(ans, min(le + ri, inf) + D[i]);
}
printf("%lld\n", ans == inf ? -1 : ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
pinball.cpp: In function 'int main()':
pinball.cpp:53:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (sz < xidx.size())sz *= 2;
~~~^~~~~~~~~~~~~
pinball.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &m, &n);
~~~~~^~~~~~~~~~~~~~~~
pinball.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |