#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
const int N = 5e3 + 10;
int n;
int a[N];
inline void build() {
for (int i = 0; i < n; ++i) {
a[i] = -1;
}
}
inline array<int,3> get(int l, int r) {
int s = 0, mn = iinf, cmn = 0;
for (int i = l; i <= r; ++i) {
s += a[i];
if (mn == a[i]) ++cmn;
else if (mn > a[i]) mn = a[i], cmn = 1;
}
return {s, mn, cmn};
}
inline void upd(int l, int r, int x) {
for (int i = l; i <= r; ++i) {
a[i] = x;
}
}
inline void solve() {
int m;
cin >> n >> m;
ve<array<int,4>> e(m);
for (auto &[l, r, k, x] : e) cin >> l >> r >> k >> x;
sort(all(e));
if (n <= 18) {
ve<int> pf(n);
for (int ma = 0; ma < (1 << n); ++ma) {
for (int i = 0; i < n; ++i) {
pf[i] = ma >> i & 1 ^ 1;
if (i) pf[i] += pf[i - 1];
}
bool ok = 1;
for (auto &[l, r, k, x] : e) {
int s = pf[r] - (!l ? 0 : pf[l - 1]);
ok &= (x == (s >= k ? 0 : 1));
}
if (ok) {
for (int i = 0; i < n; ++i) {
cout << !(pf[i] - (!i ? 0 : pf[i - 1])) << " ";
}
return;
}
}
cout << -1;
return;
}
build();
for (auto &[l, r, k, x] : e) {
if (k == 1 && x == 1) {
for (int i = l; i <= r; ++i) {
if (a[i] == 0) return void(cout << -1);
a[i] = 1;
}
}
else if (k == r - l + 1 && !x) {
for (int i = l; i <= r; ++i) {
if (a[i] == 1) return void(cout << -1);
a[i] = 0;
}
}
}
for (auto &[l, r, k, x] : e) {
if (k == 1 && x == 0) {
bool ok = 0;
for (int i = l; i <= r; ++i) {
if (a[i] == 0) {
ok = 1;
break;
}
}
if (!ok) {
for (int i = l; i <= r; ++i) {
if (a[i] == -1) {
a[i] = 0; ok = 1;
break;
}
}
}
if (!ok) return void(cout << -1);
}
else if (k == r - l + 1 && x == 1) {
bool ok = 0;
for (int i = l; i <= r; ++i) {
if (a[i] == 1) {
ok = 1;
break;
}
}
if (!ok) {
for (int i = l; i <= r; ++i) {
if (a[i] == -1) {
a[i] = 1; ok = 1;
break;
}
}
}
if (!ok) return void(cout << -1);
}
}
for (int i = 0; i < n; ++i) if (a[i] == -1) a[i] = 0;
for (int i = 0; i < n; ++i) cout << a[i] << " ";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
Compilation message
restore.cpp: In function 'void solve()':
restore.cpp:59:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
59 | pf[i] = ma >> i & 1 ^ 1;
| ~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
332 KB |
Output is correct |
4 |
Correct |
23 ms |
332 KB |
Output is correct |
5 |
Correct |
99 ms |
304 KB |
Output is correct |
6 |
Correct |
47 ms |
212 KB |
Output is correct |
7 |
Correct |
17 ms |
324 KB |
Output is correct |
8 |
Correct |
16 ms |
332 KB |
Output is correct |
9 |
Correct |
86 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
7 ms |
496 KB |
Output is correct |
8 |
Correct |
6 ms |
596 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
608 KB |
Output is correct |
11 |
Correct |
5 ms |
628 KB |
Output is correct |
12 |
Correct |
4 ms |
608 KB |
Output is correct |
13 |
Correct |
7 ms |
596 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
616 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
332 KB |
Output is correct |
4 |
Correct |
23 ms |
332 KB |
Output is correct |
5 |
Correct |
99 ms |
304 KB |
Output is correct |
6 |
Correct |
47 ms |
212 KB |
Output is correct |
7 |
Correct |
17 ms |
324 KB |
Output is correct |
8 |
Correct |
16 ms |
332 KB |
Output is correct |
9 |
Correct |
86 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
7 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
7 ms |
496 KB |
Output is correct |
18 |
Correct |
6 ms |
596 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
608 KB |
Output is correct |
21 |
Correct |
5 ms |
628 KB |
Output is correct |
22 |
Correct |
4 ms |
608 KB |
Output is correct |
23 |
Correct |
7 ms |
596 KB |
Output is correct |
24 |
Correct |
6 ms |
600 KB |
Output is correct |
25 |
Correct |
4 ms |
616 KB |
Output is correct |
26 |
Correct |
5 ms |
596 KB |
Output is correct |
27 |
Incorrect |
4 ms |
596 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |