結果

問題 No.953 席
ユーザー firiexpfiriexp
提出日時 2019-12-16 01:46:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,410 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 95,452 KB
最終ジャッジ日時 2024-11-14 21:58:04
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:19:39: error: '::numeric_limits' has not been declared
   19 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
      |                                       ^~~~~~~~~~~~~~
main.cpp:19:55: error: expected primary-expression before '>' token
   19 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
      |                                                       ^
main.cpp:19:61: error: no matching function for call to 'max()'
   19 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
      |                                                        ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
main.cpp:19:61: note:   candidate expects 2 arguments, 0 provided
   19 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
      |                                                        ~~~~~^~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'templat

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <cassert>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using P = pair<int, int>;
using P2 = pair<ll, int>;


template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "{" << p.first << ", " << p.second << "}";
}


int main() {
    int n, k1, k2;
    cin >> n >> k1 >> k2;
    vector<int> v(n);
    if(k1 < k2){
        int l = k1-1, r = k2-1, c = 0;
        while(0 <= l || r < n){
            if(0 <= l) v[l--] = c++;
            if(r < n) v[r++] = c++;
        }
    }else {
        int l = k2-1, r = k1-1, c = 0;
        while(0 <= l || r < n){
            if(r < n) v[r++] = c++;
            if(0 <= l) v[l--] = c++;

        }
    }
    auto cmp = [&](P x, P y){
        if(x.first != y.first) return x.first < y.first;
        else return v[x.second] < v[y.second];
    };
    set<P, decltype(cmp)> s(cmp);
    for (int i = 0; i < n; ++i) {
        s.emplace(0, i); // 0 : empty 1 : adjacent 2 : not empty
    }
    vector<int> data(n, 0);
    int q;
    cin >> q;

    auto update = [&](int i, int j){
        if(j == 0){
            if(i != 0 && data[i-1] == 2) j = 1;
            if(i != n-1 && data[i+1] == 2) j = 1;
        }
        if(data[i] == j) return;
        s.erase({data[i], i});
        s.emplace(j, i);
        data[i] = j;
        if(j == 2){
            if(i != 0 && !data[i-1]){
                s.erase({data[i-1], i-1});
                s.emplace(1, i-1);
                data[i-1] = 1;
            }
            if(i != n-1 && !data[i+1]){
                s.erase({data[i+1], i+1});
                s.emplace(1, i+1);
                data[i+1] = 1;
            }
        }else {
            if(i && data[i-1] == 1 && (i == 1 || data[i-2] <= 1)){
                s.erase({data[i-1], i-1});
                s.emplace(0, i-1);
                data[i-1] = 0;
            }
            if(i != n-1 && data[i+1] == 1 && (i == n-2 || data[i+2] <= 1)){
                s.erase({data[i+1], i+1});
                s.emplace(0, i+1);
                data[i+1] = 0;
            }
        }
    };
    ll cnt = 0, time = 0;
    GPQ<P2> Q;
    for (int i = 0; i < q; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        time = max<ll>(time, a);
        if(cnt == n){ // 満席なら追い出す
            time = max(time, Q.top().first);
            update(Q.top().second, 0);
            cnt--;
            Q.pop();
        }
        while(!Q.empty() && Q.top().first <= time){
            time = max(time, Q.top().first);
            update(Q.top().second, 0);
            cnt--;
            Q.pop();
        }
        auto x = *s.begin();
        if(x.first == 2) assert(0);
        printf("%d\n", x.second + 1);
        Q.emplace(time+b, x.second);
        update(x.second, 2);
        cnt++;
    }
    return 0;
}
0