Submission #258620

#TimeUsernameProblemLanguageResultExecution timeMemory
258620errorgornRestore Array (RMI19_restore)C++14
38 / 100
47 ms888 KiB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...