結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2019-12-16 01:17:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,691 bytes |
| コンパイル時間 | 1,452 ms |
| コンパイル使用メモリ | 131,872 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2024-07-02 18:46:21 |
| 合計ジャッジ時間 | 5,400 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 24 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
int n, k1, k2;
cin>>n>>k1>>k2;
//k1--; k2--;
int q;
cin>>q;
int a[100010], b[100010];
using Pi=pair<P, int>;
priority_queue<Pi, vector<Pi>, greater<Pi>> v;
vector<int> time;
for(int i=0; i<q; i++){
cin>>a[i]>>b[i];
b[i]+=a[i];
v.push({{a[i], i}, 0});
v.push({{b[i], i}, 1});
time.push_back(b[i]);
}
sort(time.begin(), time.end());
time.erase(unique(time.begin(), time.end()), time.end());
set<int> st1, st2;
bool used[100010]={};
for(int i=0; i<=n+1; i++){
st1.insert(i);
st2.insert(i);
}
queue<int> myon;
int ans[100010];
while(!v.empty()){
auto p=v.top(); v.pop();
int t=p.second;
int i=p.first.second;
if(t==0){
auto itr=st1.lower_bound(max(k1, k2));
int x=*itr;
itr--;
int y=*itr;
if(x==n+1 && y==0){
auto itr2=st2.lower_bound(max(k1, k2));
int x2=*itr2;
itr2--;
int y2=*itr2;
if(x2==n+1 && y2==0){
//auto r=v.top();
//cout<<p.first.first<<" "<<r.first.first<<endl;
v.push({{*upper_bound(time.begin(), time.end(), p.first.first), i}, t});
continue;
}else if(x2==n+1){
x=y2;
}else if(y2==0){
x=x2;
}else{
if(x2-max(k1, k2)>min(k1, k2)-y2){
x2=y2;
}else if(k1<k2 && x2-k2==k1-y2){
x2=y2;
}
x=x2;
}
}else if(x==n+1){
x=y;
}else if(y==0){
}else{
if(x-max(k1, k2)>min(k1, k2)-y){
x=y;
}else if(k1<k2 && x-k2==k1-y){
x=y;
}
}
ans[i]=x;
st2.erase(x);
st1.erase(x);
if(x>1) st1.erase(x-1);
if(x<n) st1.erase(x+1);
used[x]=1;
}else{
int x=ans[i];
used[x]=0;
st2.insert(x);
if(x-1>0){
if(!used[x-1] && !used[x-2]) st1.insert(x-1);
}
if(x+1<=n){
if(!used[x+1] && !used[x+2]) st1.insert(x+1);
}
if(!used[x-1] && !used[x+1]) st1.insert(x);
}
}
//cout<<myon.front()<<endl;
for(int i=0; i<q; i++){
cout<<ans[i]<<endl;
}
return 0;
}
chocorusk