#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 5e3 + 1, maxm = 1e4 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, block = 5000, p2 = 31, bit = 30;
const ld eps = 1e-9;
int n, m;
int l[maxm], r[maxm], k[maxm], value[maxm], ans[maxn], used[maxn];
int pref[maxn];
int subtask1 = 1, subtask2 = 1;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i){
cin >> l[i] >> r[i] >> k[i] >> value[i];
subtask1 &= (k[i] == 1);
subtask2 &= (k[i] == 1 || k[i] == r[i] - l[i] + 1);
}
if (n <= 18){
for (int i = 0; i < (1 << n); ++i){
for (int j = 0; j < n; ++j){
if ((1 << j) & i){
pref[j] += 1;
}
if (j){
pref[j] += pref[j - 1];
}
}
int bad = 0;
for (int j = 1; j <= m; ++j){
int dig = pref[r[j]] - (l[j] - 1 >= 0 ? pref[l[j] - 1] : 0);
int len = r[j] - l[j] + 1;
if (len - dig + 1 <= k[j]){
if (value[j] == 0){
bad = 1;
}
}
else{
if (value[j] == 1){
bad = 1;
}
}
}
if (!bad){
for (int j = 0; j < n; ++j){
cout << (((1 << j) & i) > 0) << " ";
}
exit(0);
}
for (int j = 0; j < n; ++j){
pref[j] = 0;
}
}
cout << -1;
exit(0);
}
if (subtask1){
for (int i = 1; i <= m; ++i){
if (value[i] == 1){
for (int j = l[i]; j <= r[i]; ++j){
ans[j] = 1;
}
}
}
for (int i = 1; i <= m; ++i){
if (value[i] == 0){
int ok = 0;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 0){
ok = 1;
}
}
if (!ok){
cout << -1;
exit(0);
}
}
}
for (int i = 0; i < n; ++i){
cout << ans[i] << " ";
}
exit(0);
}
if (subtask2){
for (int i = 1; i <= m; ++i){
if (value[i] == 1 && k[i] == 1){
for (int j = l[i]; j <= r[i]; ++j){
ans[j] = 1;
used[j] = 1;
}
}
if (value[i] == 0 && k[i] == r[i] - l[i] + 1){
for (int j = l[i]; j <= r[i]; ++j){
ans[j] = 0;
used[j] = 1;
}
}
}
int bad = 0;
for (int i = 1; i <= m; ++i){
if (value[i] == 1 && k[i] == r[i] - l[i] + 1){
int ok = 0;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 1){
ok = 1;
}
}
if (!ok){
for (int j = l[i]; j <= r[i]; ++j){
if (used[j] == 0){
ans[j] = 1;
ok = 1;
used[j] = 1;
break;
}
}
}
if (!ok){
bad = 1;
}
}
}
for (int i = 1; i <= m; ++i){
if (value[i] == 0 && k[i] == 1){
int ok = 0;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 0){
ok = 1;
}
}
if (!ok){
bad = 1;
}
}
if (value[i] == 1 && k[i] == 1){
int ok = 1;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 0){
ok = 0;
}
}
if (!ok){
bad = 1;
}
}
if (value[i] == 0 && k[i] == r[i] - l[i] + 1){
int ok = 1;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 1){
ok = 0;
}
}
if (!ok){
bad = 1;
}
}
if (value[i] == 1 && k[i] == r[i] - l[i] + 1){
int ok = 0;
for (int j = l[i]; j <= r[i]; ++j){
if (ans[j] == 1){
ok = 1;
}
}
if (!ok){
bad = 1;
}
}
}
if (bad){
cout << -1;
exit(0);
}
for (int i = 0; i < n; ++i){
cout << ans[i] << " ";
}
}
}
/*
ajj, ajj, ajj, ajj, aj, aj, aj, aj, aj, aj, ak, ak, ak, ak, ak, ai, ai, ai
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
37 ms |
332 KB |
Output is correct |
4 |
Correct |
40 ms |
340 KB |
Output is correct |
5 |
Correct |
140 ms |
320 KB |
Output is correct |
6 |
Correct |
69 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
340 KB |
Output is correct |
8 |
Correct |
22 ms |
212 KB |
Output is correct |
9 |
Correct |
143 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
500 KB |
Output is correct |
3 |
Correct |
11 ms |
468 KB |
Output is correct |
4 |
Correct |
11 ms |
496 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
500 KB |
Output is correct |
3 |
Correct |
11 ms |
468 KB |
Output is correct |
4 |
Correct |
11 ms |
496 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
420 KB |
Output is correct |
7 |
Correct |
14 ms |
524 KB |
Output is correct |
8 |
Correct |
14 ms |
468 KB |
Output is correct |
9 |
Correct |
18 ms |
468 KB |
Output is correct |
10 |
Correct |
14 ms |
520 KB |
Output is correct |
11 |
Correct |
16 ms |
524 KB |
Output is correct |
12 |
Correct |
24 ms |
468 KB |
Output is correct |
13 |
Correct |
15 ms |
528 KB |
Output is correct |
14 |
Correct |
13 ms |
528 KB |
Output is correct |
15 |
Correct |
10 ms |
468 KB |
Output is correct |
16 |
Correct |
12 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
37 ms |
332 KB |
Output is correct |
4 |
Correct |
40 ms |
340 KB |
Output is correct |
5 |
Correct |
140 ms |
320 KB |
Output is correct |
6 |
Correct |
69 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
340 KB |
Output is correct |
8 |
Correct |
22 ms |
212 KB |
Output is correct |
9 |
Correct |
143 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
14 ms |
468 KB |
Output is correct |
12 |
Correct |
14 ms |
500 KB |
Output is correct |
13 |
Correct |
11 ms |
468 KB |
Output is correct |
14 |
Correct |
11 ms |
496 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
420 KB |
Output is correct |
17 |
Correct |
14 ms |
524 KB |
Output is correct |
18 |
Correct |
14 ms |
468 KB |
Output is correct |
19 |
Correct |
18 ms |
468 KB |
Output is correct |
20 |
Correct |
14 ms |
520 KB |
Output is correct |
21 |
Correct |
16 ms |
524 KB |
Output is correct |
22 |
Correct |
24 ms |
468 KB |
Output is correct |
23 |
Correct |
15 ms |
528 KB |
Output is correct |
24 |
Correct |
13 ms |
528 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
12 ms |
524 KB |
Output is correct |
27 |
Incorrect |
3 ms |
596 KB |
Unexpected end of file - int32 expected |
28 |
Halted |
0 ms |
0 KB |
- |