結果

問題 No.953 席
ユーザー ngtkanangtkana
提出日時 2020-04-11 23:23:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,886 bytes
コンパイル時間 4,289 ms
コンパイル使用メモリ 222,696 KB
実行使用メモリ 11,240 KB
最終ジャッジ日時 2023-10-19 20:26:38
合計ジャッジ時間 9,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 46 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k0,k1,q;std::cin>>n>>k0>>k1>>q;k0--,k1--;
    std::vector<std::tuple<lint,lint,lint>>events;
    for(lint i=0;i<q;i++){
        lint a,b;std::cin>>a>>b;
        events.emplace_back(b,i,0);
        events.emplace_back(a,i,1);
    }
    auto dist_to_exit=[&](lint x){return std::abs(3*x-(2*k0+k1));};
    auto nearer=[&](lint x,lint y){return dist_to_exit(x)<dist_to_exit(y);};
    using nearer_t=std::decay_t<decltype(nearer)>;
    std::sort(ALL(events));
    std::deque<lint>wait;
    std::vector<lint>ans(q),ckd(n);
    std::array<std::set<lint,nearer_t>,2>sets{std::set<lint,nearer_t>(nearer),std::set<lint,nearer_t>(nearer)};
    for(lint i=0;i<n;i++)sets.at(0).insert(i);
    auto update=[&](lint i){
        for(auto&&set:sets)if(auto f=set.find(i);f!=set.end())set.erase(f);
        if(ckd.at(i))return;
        sets.at((i==0||!ckd.at(i-1))&&(i==n-1||!ckd.at(i+1))?0:1).insert(i);
    };
    auto update_three=[&](lint i){
        if(i)update(i-1);
        update(i);
        if(i!=n-1)update(i+1);
    };
    for(auto[_,i,c]:events){
        if(c==0){
            if(!wait.empty()){
                lint j=wait.front();wait.pop_front();
                ans.at(j)=ans.at(i);
            }else{
                ckd.at(ans.at(i))=false;
                update_three(ans.at(i));
            }
        }
        if(c==1){
            lint a=-1;
            for(auto&&set:sets){
                if(!set.empty()){
                    a=*set.begin();
                    set.erase(set.begin());
                    break;
                }
            }
            if(a==-1){
                wait.push_back(i);
            }else{
                ans.at(i)=a;
                ckd.at(a)=true;
                update_three(ans.at(i));
            }
        }
    }
    for(lint x:ans){
        std::cout<<x+1<<'\n';
    }
}
/*
 * ans[ 人 ] = 座った席です。
 * ckd[ 席 ] = 人が座っていれば true です。
 * set[ 0 ] = 両隣の空いている席の集合です。(入り口に近い順です。)
 * set[ 1 ] = 隣に人が座っているけれども空いている席の集合です。
 * wait = 待っている人の集合を、キューで管理です。
 *
 * * 退店
 * まず、その人の席を特定です。
 * 待っている方がいらっしゃれば、その方と交代し、答えを更新です。
 * いなければ、ckd を更新し、両隣含めた 3 席の set を更新です。
 *
 * * 来店
 * まず、入れる席を探しましょう。
 * 見つからなければ wait へです。
 * いなければ、ckd を更新し、両隣含めた 3 席の set を更新です。
 */
0