#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 1e4 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;
int n, m, l[N], r[N], k[N], val[N], a[N], pref[N], ones[N], zeros[N];
int sb2 = 1, can = 1, sb3 = 1;
int main(){
speed;
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> l[i] >> r[i] >> k[i] >> val[i];
l[i]++;
r[i]++;
if(k[i] != 1)
sb2 = 0;
if(k[i] != r[i] - l[i] + 1 && k[i] != 1)
sb3 = 0;
}
/*
if(sb2){
for(int i = 1; i <= m; i++){
if(val[i] == 1){
a[l[i]]++;
a[r[i] + 1]--;
}
}
for(int i = 1; i <= n; i++){
a[i] += a[i - 1];
}
for(int i = 1; i <= n; i++)
a[i] = min(a[i], 1);
for(int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + a[i];
}
for(int i = 1; i <= m; i++){
if(val[i] == 0){
if(pref[r[i]] - pref[l[i] - 1] == r[i] - l[i] + 1)
can = 0;
}
}
if(!can){
cout << -1 << endl;
return 0;
}
for(int i = 1; i <= n; i++){
cout << a[i] << " ";
}
return 0;
}
*/
if(sb3){
for(int i = 1; i <= m; i++){
if(val[i] == 0 && k[i] == r[i] - l[i] + 1){
zeros[l[i]] += 1;
zeros[r[i] + 1] -= 1;
}
if(val[i] == 1 && k[i] == 1){
ones[l[i]] += 1;
ones[r[i] + 1] -= 1;
}
}
for(int i = 1; i <= n; i++){
zeros[i] += zeros[i - 1];
ones[i] += ones[i - 1];
}
for(int i = 1; i <= n; i++){
zeros[i] = min(zeros[i], 1);
ones[i] = min(ones[i], 1);
if(zeros[i] == 1 && ones[i] == 1) can = 0;
}
if(!can){
cout << -1 << endl;
return 0;
}
vector <int> vt[N];
for(int i = 1; i <= m; i++){
if(val[i] == 0 && k[i] == r[i] - l[i] + 1) continue;
if(val[i] == 1 && k[i] == 1) continue;
vt[l[i]].pb(i);
}
set <pii> st;
for(int i = 1; i <= n; i++){
if((st.begin() -> first) < i){
can = 0;
break;
}
for(auto to : vt[i]){
st.insert({r[to], to});
}
if(zeros[i] == 0 && ones[i] == 0){
int idx = (st.begin() -> second);
st.erase(st.begin());
if(val[idx] == 0)
zeros[idx] = 1;
else
ones[idx] = 1;
}
}
if(st.size() != 0) can = 0;
if(!can){
cout << -1 << endl;
return 0;
}
for(int i = 1; i <= n; i++){
if(ones[i])
cout << 1 << " ";
else if(zeros[i])
cout << 0 << " ";
else
cout << 0 << " ";
}
}
}
/*
%I64d6
6 1 3
8 1 2 1 5 4
%I64d
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |