# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1106844 | VectorLi | Restore Array (RMI19_restore) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = (int) 2E5;
int n, m;
vector<pair<int, int>> e[N + 1];
int d[N + 1];
priority_queue<pair<int, int>> q;
void Dijkstra(int x) {
fill(d, d + n + 1, numeric_limits<int>::max());
d[x] = 0;
q.push({0 - d[x], x});
while (q.empty() == 0) {
auto [t, u] = q.top();
q.pop();
t = 0 - t;
if (t != d[u]) {
continue;
}
for (auto [v, w] : e[u]) {
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
q.push({0 - d[v], v});
}
}
}
}
void solve() {
cin >> n >> m;
for (int i = 0; i <= n - 1; i++) {
e[i + 1].push_back({i, 0});
e[i].push_back({i + 1, 1});
}
for (int i = 0; i < m; i++) {
int l, r;
int k, x;
cin >> l >> r >> k >> x;
l = l + 1;
r = r + 1;
if (x == 0) {
e[r].push_back({l - 1, k});
} else {
e[l - 1].push_back({r, (k - 1)});
}
}
Dijkstra(0);
if (find(d, d + n + 1, numeric_limits<int>::max() != d + n + 1) {
cout << 0 - 1 << "\n";
exit(0);
}
for (int i = 1; i <= n; i++) {
if (d[i] - d[i - 1] == 0) {
cout << 1 << " ";
} else {
cout << 0 << " ";
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int t;
t = 1;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}