Submission #259654

# Submission time Handle Problem Language Result Execution time Memory
259654 2020-08-08T06:58:34 Z errorgorn Santa Claus (RMI19_santa) C++14
0 / 100
1000 ms 2812 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#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>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
int pos[100005];
int type[100005];
int val[100005];
int ans[100005];

bool test(int l,int r){
	multiset<int> s;
	
	rep(x,0,r+1){
		if (x<l){
			if (type[x]==0){
				s.insert(val[x]);
			}
		}
		else if (x==l){
			rep(x,l,r+1) if (type[x]==0){
				s.insert(val[x]);
			}
		}
		
		if (type[x]==1){
			auto it=s.lower_bound(val[x]);
			if (it!=s.end()) s.erase(it);
		}
	}
	
	//cout<<l<<" "<<r<<" "<<sz(s)<<endl;
	return s.empty();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int TC;
	cin>>TC;
	while (TC--){
		cin>>n;
		rep(x,0,n) cin>>pos[x];
		rep(x,0,n) cin>>type[x];
		rep(x,0,n) cin>>val[x];
		
		bool bad=false;
		rep(x,n,0){
			if (type[x]==0) bad=true;
			
			if (bad) ans[x]=-1;
			else{
				if (!test(0,x)){
					ans[x]=-1;
					bad=true;
					continue;
				}
				
				int lo=0,hi=x+1,mi;
				
				while (hi-lo>1){
					mi=hi+lo>>1;
					
					if (test(mi,x)) lo=mi;
					else hi=mi;
				}
				
				//cout<<x<<" "<<lo<<endl;
				ans[x]=2*pos[x]-pos[lo];
			}
		}
		
		rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
	}
}

Compilation message

santa.cpp: In function 'int main()':
santa.cpp:94:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      mi=hi+lo>>1;
         ~~^~~
santa.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--))
                          ^
santa.cpp:105:3: note: in expansion of macro 'rep'
   rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
   ^~~
santa.cpp:105:33: 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;
                                 ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Incorrect 16 ms 384 KB Output isn't correct
3 Execution timed out 1082 ms 632 KB Time limit exceeded
4 Execution timed out 1090 ms 632 KB Time limit exceeded
5 Execution timed out 1091 ms 512 KB Time limit exceeded
6 Execution timed out 1090 ms 768 KB Time limit exceeded
7 Execution timed out 1086 ms 1152 KB Time limit exceeded
8 Execution timed out 1087 ms 1408 KB Time limit exceeded
9 Execution timed out 1086 ms 2808 KB Time limit exceeded
10 Execution timed out 1078 ms 2812 KB Time limit exceeded