#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) 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;
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
256 KB |
Output is correct |
4 |
Correct |
20 ms |
212 KB |
Output is correct |
5 |
Correct |
104 ms |
304 KB |
Output is correct |
6 |
Correct |
46 ms |
308 KB |
Output is correct |
7 |
Correct |
20 ms |
212 KB |
Output is correct |
8 |
Correct |
18 ms |
212 KB |
Output is correct |
9 |
Correct |
104 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
256 KB |
Output is correct |
4 |
Correct |
20 ms |
212 KB |
Output is correct |
5 |
Correct |
104 ms |
304 KB |
Output is correct |
6 |
Correct |
46 ms |
308 KB |
Output is correct |
7 |
Correct |
20 ms |
212 KB |
Output is correct |
8 |
Correct |
18 ms |
212 KB |
Output is correct |
9 |
Correct |
104 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Incorrect |
5 ms |
468 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |