#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 1e5;
int n, m;
int l[mxn], r[mxn], k[mxn], val[mxn];
void brute_force(){
int mat[n][n];
fr(i, 0, n){
int bit = 0;
fr(j, i, n){
bit|=(1<<j);
mat[i][j] = bit;
}
}
int ANS = -1;
fr(mask, 0, (1<<n)){
bool ok = true;
fr(i, 0, m){
int len = r[i]-l[i]+1;
int cnt = __builtin_popcount(mask&mat[l[i]][r[i]]);
if(val[i] == 0 && k[i] > len-cnt){
ok = false;
break;
}
if(val[i] == 1 && cnt < len - k[i]+1){
ok = false;
break;
}
}
if(ok){
ANS = mask;
break;
}
}
if(ANS == -1){
cout<<-1<<endl;
}
else{
fr(i, 0, n){
if(ANS&(1<<i)) cout<<1<<' ';
else cout<<0<<' ';
}
cout<<endl;
}
}
void K1(){
int ans[n];
memset(ans, 0, sizeof(ans));
fr(i, 0, m){
if(val[i] == 0) continue;
fr(j, l[i], r[i]+1){
ans[j] = 1;
}
}
fr(i, 0, m){
if(val[i] == 1) continue;
bool ok = false;
fr(j, l[i], r[i]+1){
if(ans[j] == 0){
ok = true;
break;
}
}
if(!ok){
cout<<-1<<endl;
return;
}
}
fr(i, 0, n){
cout<<ans[i]<<' ';
}
cout<<endl;
}
void K12(){
int ans[n];
memset(ans, -1, sizeof(ans));
vector<pii> v[2];
fr(i, 0, m){
int len[2] = {r[i]-l[i]+1, 1};
if(k[i] == len[val[i]]){
fr(j, l[i], r[i]){
ans[j] = val[i];
}
}
if(len[0] != 2) continue;
v[val[i]].pb({l[i], r[i]});
}
fr(i, 0, n){
fr(col, 0, 2){
for(auto u : v[col]){
if(ans[u.st] == -1 && ans[u.nd] == -1) continue;
if(ans[u.st] == col || ans[u.nd] == col) continue;
if(ans[u.st] == -1){
ans[u.st] = col;
}
else if(ans[u.nd] == -1){
ans[u.nd] = col;
}
}
}
}
if(ans[0] == -1) ans[0] = 0;
fr(i, 1, n){
if(ans[i] == -1) ans[i] = ans[i-1]^1;
}
fr(i, 0, m){
int c1 = 0;
int c0 = 0;
fr(j, l[i], r[i]+1){
if(ans[j] == 1) c1 ++;
else c0 ++;
}
if(k[i] == 1){
if(val[i] == 0){
if(c0 == 0){
cout<<-1<<endl;
return;
}
}
else{
if(c0 != 0){
cout<<-1<<endl;
return;
}
}
}
else{
if(val[i] == 0){
if(c1 != 0){
cout<<-1<<endl;
return;
}
}
else{
if(c1 == 0){
cout<<-1<<endl;
return;
}
}
}
}
fr(i, 0, n){
cout<<ans[i]<<' ';
}
cout<<endl;
}
void solve(){
cin >> n >> m;
bool k1 = true;
bool k12 = true;
fr(i, 0, m){
cin >> l[i] >> r[i] >> k[i] >> val[i];
if(k[i] != 1) k1 = false;
if(k[i] > 1 && k[i] < r[i]-l[i]+1) k12 = false;
}
if(n < 20){
brute_force();
}
else if(k1){
K1();
}
else if(k12){
K12();
}
else{
cout<<-1<<endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
10 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
10 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
24 ms |
608 KB |
Output is correct |
8 |
Correct |
15 ms |
640 KB |
Output is correct |
9 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
512 KB |
Output is correct |
15 |
Correct |
10 ms |
512 KB |
Output is correct |
16 |
Correct |
7 ms |
512 KB |
Output is correct |
17 |
Correct |
24 ms |
608 KB |
Output is correct |
18 |
Correct |
15 ms |
640 KB |
Output is correct |
19 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |