#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<int> l(m + 1), r(m + 1), k(m + 1), v(m + 1);
std::vector<std::array<int, 3>> e[n];
std::vector<int> ans(n, - 1);
for(int i = 1; i <= m; i++) {
std::cin >> l[i] >> r[i] >> k[i] >> v[i];
if(v[i] == 1) {
int w = r[i] - (l[i] + k[i] - 1) + 1;
e[l[i]].push_back({r[i], v[i], w});
}
else {
int w = l[i] + (k[i] - 1) - (l[i]) + 1;
e[l[i]].push_back({r[i], v[i], w});
}
}
int ok = 1;
for(int i = 0; i < n && ok; i++) {
for(int j = 0; j < e[i].size(); j++) {
int to = e[i][j][0];
int st = e[i][j][1];
int cnt = e[i][j][2];
int found = 0;
for(int x = i; x <= to; x++) {
if(ans[x] == st) {
found += 1;
}
}
if(found >= cnt) {
continue;
}
int can = 0;
for(int x = i; x <= to; x++) {
if(ans[x] == - 1) {
can += 1;
}
}
if(can < cnt - found) {
ok = 0;
break;
}
int have_to = can - (cnt - found);
for(int x = i; x <= to && have_to > 0; x++) {
if(ans[x] == - 1) {
ans[x] = st;
have_to--;
}
}
}
}
if(!ok) {
std::cout << - 1;
return 0;
}
for(int i = 0; i < n; i++) {
if(ans[i] == - 1) {
ans[i] = 0;
}
std::cout << ans[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... |