結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
%20
|
| 提出日時 | 2019-12-16 04:33:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 2,000 ms |
| コード長 | 1,334 bytes |
| コンパイル時間 | 2,948 ms |
| コンパイル使用メモリ | 211,096 KB |
| 最終ジャッジ日時 | 2025-01-08 11:45:05 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pli=pair<ll,int>;
int main(){cin.tie(0);ios::sync_with_stdio(false);
int N,K1,K2;cin>>N>>K1>>K2;
vector<int>f(N+2),g(3*N);
for(int i=1;i<=N;++i){
int t=2*abs(i-K1)+abs(i-K2);
f[i]=t;
g[t]=i;
}
set<int>good,bad;
for(int i=1;i<=N;++i){
good.insert(f[i]);
}
vector<bool>v(N+1);
int Q;cin>>Q;
priority_queue<pli,vector<pli>,greater<pli>>pq;
ll time=0;
for(int _=0;_<Q;++_){
ll A,B;cin>>A>>B;
time=max(time,A);
redo:
while(pq.size()&&pq.top().first<=time){
int k=pq.top().second;pq.pop();
v[k]=false;
if((k-1<1||!v[k-1])&&(k+1>N||!v[k+1])){
good.insert(f[k]);
}else{
bad.insert(f[k]);
}
if(k>1&&!v[k-1]&&(k-2<1||!v[k-2])){
bad.erase(f[k-1]);
good.insert(f[k-1]);
}
if(k<N&&!v[k+1]&&(k+2>N||!v[k+2])){
bad.erase(f[k+1]);
good.insert(f[k+1]);
}
}
int k;
if(good.size()){
k=*good.begin();
good.erase(k);
}else if(bad.size()){
k=*bad.begin();
bad.erase(k);
}else{
assert(time<pq.top().first);
time=pq.top().first;
goto redo;
}
k=g[k];
cout<<k<<"\n";
pq.push({time+B,k});
v[k]=true;
if(good.count(f[k-1])){
good.erase(f[k-1]);
bad.insert(f[k-1]);
}
if(good.count(f[k+1])){
good.erase(f[k+1]);
bad.insert(f[k+1]);
}
}
return 0;
}
%20