結果

問題 No.953 席
ユーザー WarToksWarToks
提出日時 2020-01-03 00:37:33
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,815 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 113,668 KB
実行使用メモリ 10,628 KB
最終ジャッジ日時 2023-08-20 13:39:22
合計ジャッジ時間 5,409 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 134 ms
9,744 KB
testcase_08 AC 104 ms
7,900 KB
testcase_09 AC 113 ms
10,628 KB
testcase_10 AC 37 ms
5,632 KB
testcase_11 AC 80 ms
6,720 KB
testcase_12 WA -
testcase_13 AC 94 ms
7,600 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 103 ms
7,888 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 98 ms
7,708 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int N = 1e5;
std::bitset<N> Invacant; // 座っているか否か
std::vector<char> Neighborhood; // 隣の人が空か
std::vector<int> Res; // 答え

std::vector<int> Priority; // 近さの順位
std::vector<std::pair<int, int>> Ppriority;


 
int main(void){
    int n, k1, k2; scanf("%d%d%d", &n, &k1, &k2); k1--; k2--;

    // 座席の優先順位の決定
    Ppriority.resize(n);
    REP(i, n){
        // (2 * k1 + k2)/3 - t = |2k1 + k2 - 3t|/3
        int u = 2 * k1 + k2 - 3 * i; if(u < 0) u *= -1;
        Ppriority[i] = {u, i};
    }
    std::sort(Ppriority.begin(), Ppriority.end());
    Priority.resize(n);
    REP(i, n) Priority[Ppriority[i].second] = i;


    Neighborhood.assign(n, 1);

    int q; scanf("%d", &q);
    Res.resize(q, -1);

    
    // 退店時刻, インデックス
    using datum = std::pair<int, int>;
    std::queue<std::pair<int, int>> Q;
    std::priority_queue<datum, std::vector<datum>, std::greater<datum>> PQ;
    std::set<std::pair<bool, std::pair<int, int>>> S;

    REP(i, n) S.insert({false, {Priority[i], i}});

    std::function<void(int, bool)> update = [&](int seat, bool inc){
        if(seat < 0 or seat >= n) return; // 例外
        if(Invacant[seat]){
            if(inc) Neighborhood[seat]++; else Neighborhood[seat]--;
            return;
        }
        S.erase({Neighborhood[seat] <= 0, {Priority[seat], seat}});
        if(inc) Neighborhood[seat]++; else Neighborhood[seat]--;
        S.insert({Neighborhood[seat] <= 0, {Priority[seat], seat}});
    };

    REP(i, q){
        int a, b; scanf("%d%d", &a, &b);

        // i番目を座らせる前に起きる退店-待ちイベントを処理する
        while((not PQ.empty()) and PQ.top().first <= a){
            int theTime = PQ.top().first;
            while((not PQ.empty()) and PQ.top().first == theTime){ // 同時刻に帰る客を全員帰らせる
                int t, idx;
                std::tie(t, idx) = PQ.top(); PQ.pop();
                // 退店処理
                int seat = Res[idx];
                Invacant[seat] = false;
                update(seat - 1, true); update(seat + 1, true);
                S.insert({Neighborhood[seat] <= 0, {Priority[seat], seat}});
            }
            
            while((not Q.empty()) and (not S.empty())){ // お待ちのお客様!
                // 入店処理
                auto val = *S.begin(); S.erase(S.begin());
                int seat = val.second.second;
                Invacant[seat] = true;
                update(seat - 1, false);
                update(seat + 1, false);
                // 
                int member, length;
                std::tie(member, length) = Q.front(); Q.pop();
                Res[member] = seat;
                PQ.push({theTime + length, member});
            }
        }
        if(S.empty()) Q.push({i, b}); // 待つ場合
        else{
            auto val = *S.begin(); S.erase(S.begin());
            int seat = val.second.second;
            Invacant[seat] = true;
            update(seat - 1, false);
            update(seat + 1, false);
            Res[i] = seat;
            PQ.push({a + b, i});
        }
    }

    while(not Q.empty()){

            int theTime = PQ.top().first;
            while((not PQ.empty()) and PQ.top().first == theTime){ // 同時刻に帰る客を全員帰らせる
                int t, idx;
                std::tie(t, idx) = PQ.top(); PQ.pop();
                // 退店処理
                int seat = Res[idx];
                Invacant[seat] = false;
                update(seat - 1, true); update(seat + 1, true);
                S.insert({Neighborhood[seat] <= 0, {Priority[seat], seat}});
            }

                    
        while((not Q.empty()) and (not S.empty())){ // お待ちのお客様!
            // 入店処理
            auto val = *S.begin(); S.erase(S.begin());
            int seat = val.second.second;
            Invacant[seat] = true;
            update(seat - 1, false);
            update(seat + 1, false);
            
            int member, length;
            std::tie(member, length) = Q.front(); Q.pop();
            Res[member] = seat;
            PQ.push({theTime + length, member});
        }
    }

    REP(i, q) printf("%d\n", Res[i] + 1);


    
    
    return 0;
}
0