結果

問題 No.953 席
ユーザー 👑 kmjpkmjp
提出日時 2019-12-16 01:22:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,223 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 195,476 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-07-02 18:46:44
合計ジャッジ時間 13,466 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 431 ms
15,232 KB
testcase_08 AC 484 ms
17,920 KB
testcase_09 AC 378 ms
14,208 KB
testcase_10 AC 118 ms
7,168 KB
testcase_11 AC 365 ms
14,336 KB
testcase_12 RE -
testcase_13 AC 473 ms
18,688 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 361 ms
18,432 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 500 ms
18,816 KB
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K1,K2,M;
int order[101010];
ll X[101010],Y[101010];

set<pair<int,int>> A;
set<pair<int,int>> B;
map<ll,vector<int>> ev;
int ret[101010];

void fix(int x) {
	if(A.count({order[x],x})==0 && B.count({order[x],x})==0) return;
	int nei=0;
	if(x>1&&A.count({order[x-1],x-1})==0 && B.count({order[x-1],x-1})==0) nei++;
	if(x<N&&A.count({order[x+1],x+1})==0 && B.count({order[x+1],x+1})==0) nei++;
	
	if(nei==0) {
		B.erase({order[x],x});
		A.insert({order[x],x});
	}
	else {
		A.erase({order[x],x});
		B.insert({order[x],x});
	}
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K1>>K2;
	x=0;
	if(K1<K2) {
		FOR(i,N) {
			if(K1-i>=1) order[K1-i]=x++;
			if(K2+i<=N) order[K2+i]=x++;
		}
	}
	else {
		FOR(i,N) {
			if(K1+i<=N) order[K1+i]=x++;
			if(K2-i>=1) order[K2-i]=x++;
		}
	}
	FOR(i,N) A.insert({order[i+1],i+1});
	
	cin>>M;
	FOR(i,M) {
		cin>>X[i]>>Y[i];
		ev[X[i]].push_back(M+i);
	}
	
	queue<int> Q;
	while(ev.size()) {
		ll t=ev.begin()->first;
		assert(t<1LL<<31);
		auto V=ev.begin()->second;
		ev.erase(ev.begin());
		sort(ALL(V));
		
		FORR(x,V) {
			if(x<M) {
				B.insert({order[ret[x]],ret[x]});
				fix(ret[x]);
				fix(ret[x]-1);
				fix(ret[x]+1);
			}
			else {
				Q.push(x-M);
			}
		}
		
		while(Q.size() && (A.size()+B.size())) {
			x=Q.front();
			Q.pop();
			if(A.size()) {
				ret[x]=A.begin()->second;
				A.erase(A.begin());
			}
			else {
				ret[x]=B.begin()->second;
				B.erase(B.begin());
			}
			ev[t+Y[x]].push_back(x);
			fix(ret[x]-1);
			fix(ret[x]+1);
		}
	}
	
	
	FOR(i,M) cout<<ret[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0