//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct dat{
int l,r;
int val;
int len=0;
bool used=false;
};
int n,k;
int ans[5005];
dat arr[10005];
void rage(){
cout<<"-1"<<endl;
exit(0);
}
vector<int> proc; //those with len==1
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(ans,-1,sizeof(ans));
cin>>n>>k;
int a,b,c,d;
int idx=0;
rep(x,0,k){
cin>>a>>b>>c>>d;
if (c==b-a+1 && d==0){
rep(x,a,b+1){
if (ans[x]==1) rage();
ans[x]=0;
}
}
else if (c==1 && d==1){
rep(x,a,b+1){
if (ans[x]==0) rage();
ans[x]=1;
}
}
else if (d==0){ //exists 0
arr[idx].l=a;
arr[idx].r=b;
arr[idx].val=0;
idx++;
}
else{
arr[idx].l=a;
arr[idx].r=b;
arr[idx].val=1;
idx++;
}
}
rep(x,0,idx){
rep(y,arr[x].l,arr[x].r+1){
if (ans[y]==-1) arr[x].len++;
else if (ans[y]==arr[x].val) arr[x].used=true;
}
if (arr[x].len<=1) proc.push_back(x);
}
while (!proc.empty()){
int node=proc.back();
proc.pop_back();
if (arr[node].used) continue;
if (arr[node].len==0) rage();
int pos;
rep(y,arr[node].l,arr[node].r+1){
if (ans[y]==-1) pos=y;
}
ans[pos]=arr[node].val;
rep(x,0,idx) if (!arr[x].used){
if (arr[x].l<=pos && pos<=arr[x].r){
if (arr[node].val==arr[x].val) arr[x].used=true;
arr[x].len--;
if (arr[x].len==1) proc.push_back(x);
}
}
}
//rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
int curr=0;
rep(x,0,n){
if (ans[x]==-1){
ans[x]=curr;
curr^=1;
}
}
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
}
Compilation message
restore.cpp: In function 'int main()':
restore.cpp:19:26: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
^
restore.cpp:134:2: note: in expansion of macro 'rep'
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
^~~
restore.cpp:134:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
^~~~
restore.cpp:114:11: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
ans[pos]=arr[node].val;
~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
640 KB |
Output is correct |
2 |
Correct |
46 ms |
640 KB |
Output is correct |
3 |
Correct |
44 ms |
640 KB |
Output is correct |
4 |
Correct |
44 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
640 KB |
Output is correct |
2 |
Correct |
46 ms |
640 KB |
Output is correct |
3 |
Correct |
44 ms |
640 KB |
Output is correct |
4 |
Correct |
44 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
47 ms |
760 KB |
Output is correct |
8 |
Correct |
47 ms |
760 KB |
Output is correct |
9 |
Correct |
46 ms |
760 KB |
Output is correct |
10 |
Correct |
43 ms |
760 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
43 ms |
760 KB |
Output is correct |
14 |
Correct |
19 ms |
888 KB |
Output is correct |
15 |
Correct |
20 ms |
768 KB |
Output is correct |
16 |
Correct |
27 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |