結果
| 問題 | No.953 席 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-01-03 00:35:06 | 
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 5,793 bytes | 
| コンパイル時間 | 1,724 ms | 
| コンパイル使用メモリ | 150,476 KB | 
| 実行使用メモリ | 10,624 KB | 
| 最終ジャッジ日時 | 2024-11-30 15:59:53 | 
| 合計ジャッジ時間 | 6,472 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 8 WA * 17 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#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;
}
            
            
            
        