結果
問題 | No.953 席 |
ユーザー | 👑 kmjp |
提出日時 | 2019-12-16 00:33:59 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 479 ms / 2,000 ms |
コード長 | 2,561 bytes |
コンパイル時間 | 2,385 ms |
コンパイル使用メモリ | 191,592 KB |
実行使用メモリ | 18,724 KB |
最終ジャッジ日時 | 2023-09-15 15:56:53 |
合計ジャッジ時間 | 12,641 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 263 ms
16,652 KB |
testcase_03 | AC | 252 ms
16,636 KB |
testcase_04 | AC | 260 ms
16,564 KB |
testcase_05 | AC | 233 ms
16,352 KB |
testcase_06 | AC | 264 ms
16,724 KB |
testcase_07 | AC | 416 ms
15,156 KB |
testcase_08 | AC | 468 ms
17,904 KB |
testcase_09 | AC | 359 ms
14,192 KB |
testcase_10 | AC | 115 ms
7,256 KB |
testcase_11 | AC | 338 ms
14,364 KB |
testcase_12 | AC | 395 ms
17,896 KB |
testcase_13 | AC | 466 ms
18,724 KB |
testcase_14 | AC | 361 ms
17,520 KB |
testcase_15 | AC | 349 ms
17,424 KB |
testcase_16 | AC | 353 ms
17,480 KB |
testcase_17 | AC | 315 ms
17,724 KB |
testcase_18 | AC | 295 ms
17,792 KB |
testcase_19 | AC | 358 ms
18,504 KB |
testcase_20 | AC | 297 ms
17,516 KB |
testcase_21 | AC | 255 ms
16,760 KB |
testcase_22 | AC | 410 ms
18,088 KB |
testcase_23 | AC | 305 ms
17,096 KB |
testcase_24 | AC | 305 ms
16,988 KB |
testcase_25 | AC | 479 ms
18,676 KB |
testcase_26 | AC | 219 ms
16,352 KB |
ソースコード
#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(x<1 || x>N) return; 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; int pret=-1; while(ev.size()) { ll t=ev.begin()->first; auto V=ev.begin()->second; ev.erase(ev.begin()); sort(ALL(V)); FORR(v,V) if(v<M) { x=v; B.insert({order[ret[x]],ret[x]}); fix(ret[x]); fix(ret[x]-1); fix(ret[x]+1); } while(Q.size() && (A.size()+B.size())) { x=Q.front(); if(A.size()) { auto p2=*A.begin(); A.erase(A.begin()); ret[x]=p2.second; } else { auto p2=*B.begin(); B.erase(B.begin()); ret[x]=p2.second; } ev[t+Y[x]].push_back(x); fix(ret[x]-1); fix(ret[x]+1); Q.pop(); } FORR(v,V) if(v>=M) { x=v-M; if(A.size()) { ret[x]=A.begin()->second; A.erase(A.begin()); } else if(B.size()) { ret[x]=B.begin()->second; B.erase(B.begin()); } if(ret[x]==0) { Q.push(x); } else { 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; }