답안 #261009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261009 2020-08-11T09:51:17 Z ryansee Santa Claus (RMI19_santa) C++14
20 / 100
651 ms 73080 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x,v) memset(x,v,sizeof(x))
#define siz(x) ll(x.size())
#define all(x) (x).begin(),(x).end()
#define lbd(x,y) (lower_bound(all(x),y)-(x).begin())
#define ubd(x,y) (upper_bound(all(x),y)-(x).begin())
mt19937 rng(123);
long long rand(long long x,long long y){return rng() % (y+1-x) + x; }
string to_string(char c){string s(1,c);return s;}

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
ll t, n, A[MAXN], H[MAXN], T[MAXN], V[MAXN];
struct node {
	int s,e,m;
	ll v,add;
	node*l,*r;
	node(int S,int E){
		s=S,e=E,m=(s+e)>>1;
		v=add=0;
		if(s^e)l=new node(s,m),r=new node(m+1,e);
	}
	ll value(){
		v+=add;
		if(s^e){
			l->add+=add,r->add+=add;
		}
		add=0;
		return v;
	}
	void update(int x,int y,ll nval){
		if(s==x&&e==y) { add+=nval; return; }
		if(x>m) r->update(x,y,nval);
		else if(y<=m) l->update(x,y,nval);
		else l->update(x,m,nval), r->update(m+1,y,nval);
		v=min(l->value(),r->value());
	}
	ll rmq(int x,int y){
		value();
		if(s==x&&e==y) return v;
		if(x>m) return r->rmq(x,y);
		else if(y<=m) return l->rmq(x,y);
		else return min(l->rmq(x,m),r->rmq(m+1,y));
	}
} *seg;
int main(){
	FAST
	cin>>t;
	while(t--){
		cin>>n;
		seg=new node(1, n);
		FOR(i,1,n) cin>>A[i];
		FOR(i,1,n) cin>>H[i];
		FOR(i,1,n) cin>>V[i];
		ll elf = count(H+1, H+n+1, 0);
		if(elf == 0) {
			FOR(i,1,n) cout<<"0 "; 
			cout<<'\n';
			continue;
		}
		ll co = 1;
		multiset<ll> take;
		FOR(i,1,n){
			elf -= !H[i];
			if(H[i]){
				seg->update(V[i], n, 1);
			}else{
				seg->update(V[i], n, -1);
			}
			if(elf || seg->value() < 0) {
				cout<<"-1 ";
			}else{
				while(co < i){
					if(H[co]==0) { ++ co; take.ins(V[co]); continue; }
					auto gift=take.lower_bound(V[co]);
					if(gift!=take.end()) seg->update(*gift, n, 1);
					seg->update(V[co], n, -1);
					if(seg->value() < 0){
						seg->update(V[co], n, 1);
						if(gift!=take.end()) seg->update(*gift, n, -1);
						break;
					}
					++ co;
					if(gift!=take.end())take.erase(gift);
				}
				cout<<A[i]*2-A[co]<<' ';
			}
		}
		cout<<'\n';
		delete seg;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Incorrect 12 ms 2176 KB Output isn't correct
4 Incorrect 30 ms 4728 KB Output isn't correct
5 Incorrect 64 ms 9592 KB Output isn't correct
6 Incorrect 107 ms 15156 KB Output isn't correct
7 Incorrect 205 ms 26744 KB Output isn't correct
8 Incorrect 335 ms 40696 KB Output isn't correct
9 Incorrect 439 ms 51640 KB Output isn't correct
10 Incorrect 651 ms 73080 KB Output isn't correct