結果

問題 No.953 席
ユーザー mtsdmtsd
提出日時 2019-12-16 23:38:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 5,039 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 128,596 KB
実行使用メモリ 8,196 KB
最終ジャッジ日時 2023-09-15 18:58:04
合計ジャッジ時間 5,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 86 ms
4,440 KB
testcase_03 AC 82 ms
4,376 KB
testcase_04 AC 86 ms
4,376 KB
testcase_05 AC 71 ms
4,380 KB
testcase_06 AC 87 ms
4,412 KB
testcase_07 AC 122 ms
7,892 KB
testcase_08 AC 129 ms
7,052 KB
testcase_09 AC 105 ms
8,196 KB
testcase_10 AC 35 ms
4,836 KB
testcase_11 AC 93 ms
5,960 KB
testcase_12 AC 104 ms
6,104 KB
testcase_13 AC 117 ms
7,032 KB
testcase_14 AC 99 ms
5,740 KB
testcase_15 AC 97 ms
5,404 KB
testcase_16 AC 99 ms
5,528 KB
testcase_17 AC 90 ms
5,972 KB
testcase_18 AC 90 ms
5,704 KB
testcase_19 AC 108 ms
6,868 KB
testcase_20 AC 93 ms
5,828 KB
testcase_21 AC 84 ms
4,580 KB
testcase_22 AC 108 ms
6,452 KB
testcase_23 AC 93 ms
4,844 KB
testcase_24 AC 92 ms
4,964 KB
testcase_25 AC 130 ms
7,124 KB
testcase_26 AC 46 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int long long

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k1,k2;
    bool f = 0;
    cin >> n >> k1 >> k2;
    if(k1< k2){
        f = 1;
    }
    set<int> A,B,C;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> > T;
    int q;
    cin >> q;
    rep(i,n){
        A.insert(i+1);
    }
    int time = 0;
    vector<int> res(q+1);
    rep(i,q){
        int a,b;
        cin >> a >> b;
        time = max(a,time);
        while(!T.empty()){
            auto x = T.top();
            if(x.first <= time){
                T.pop();
                int k = x.second;
                C.erase(k);
                if(B.count(k-1)==1){
                    if(C.count(k-2)==0){
                        B.erase(k-1);
                        A.insert(k-1);
                    }
                }
                if(B.count(k+1)==1){
                    if(C.count(k+2)==0){
                        B.erase(k+1);
                        A.insert(k+1);
                    }
                }
                if(C.count(k-1)==1||C.count(k+1)==1){
                    B.insert(k);
                }else{
                    A.insert(k);
                }
            }else{
                break;
            }
        }
        if(C.size()==n){
            auto yy = T.top();
            time = yy.first;
            while(!T.empty()){
                auto x = T.top();
                if(x.first == time){
                    T.pop();
                    int k = x.second;
                    C.erase(k);
                    if(B.count(k-1)==1){
                        if(C.count(k-2)==0){
                            B.erase(k-1);
                            A.insert(k-1);
                        }
                    }
                    if(B.count(k+1)==1){
                        if(C.count(k+2)==0){
                            B.erase(k+1);
                            A.insert(k+1);
                        }
                    }
                    if(C.count(k-1)==1||C.count(k+1)==1){
                        B.insert(k);
                    }else{
                        A.insert(k);
                    }
                }else{
                    break;
                }
            }
        }
        if(A.size()!=0){
            auto ppp = A.lower_bound(k1);
            int L = -inf;
            if(ppp!=A.begin()){
                ppp--;
                L = *ppp;
            } 
            auto qqq =A.lower_bound(k1); 
            int R = inf;
            if(qqq!=A.end()){
                R = *qqq;
            }
            if(f){
                if(R-k1 <= k1-L){
                    res[i+1] = R;
                }else{
                    res[i+1] = L;
                }
            }else{
                if(k1-L <= R-k1){
                    res[i+1] = L ;
                }else{
                    res[i+1] = R;
                }
            }         
        }else{
            auto ppp = B.lower_bound(k1);
            int L = -inf;
            if(ppp!=B.begin()){
                ppp--;
                L = *ppp;
            } 
            auto qqq =B.lower_bound(k1); 
            int R = inf;
            if(qqq!=B.end()){
                R = *qqq;
            }
            if(f){
                
                if(R-k1 <= k1-L){
                    res[i+1] = R;
                }else{
                    res[i+1] = L;
                }
            }else{    
                if(k1-L <= R-k1){
                    res[i+1] = L ;
                }else{
                    res[i+1] = R;
                }
            }    
        }
        A.erase(res[i+1]);
        B.erase(res[i+1]);
        C.insert(res[i+1]);
        if(A.count(res[i+1]-1)){
            A.erase(res[i+1]-1);
            B.insert(res[i+1]-1);
        }
        if(A.count(res[i+1]+1)){
            A.erase(res[i+1]+1);
            B.insert(res[i+1]+1);
        }
        T.push(MP(time+b,res[i+1]));
        // cerr << "time:" << time << endl;
        // cerr << "seat:" << res[i+1] << endl;
        // for(auto x:A){
        //     cerr << x << " ";
        // }
        // cerr << endl;
        // for(auto x:B){
        //     cerr << x << " " ;
        // }
        // cerr << endl;
        // for(auto x:C){
        //     cerr << x << " ";
        // }
        // cerr << endl;
    }
    for(int i=1;i<=q;i++){
        cout << res[i] << "\n";
    }
    return 0;
}
0