結果

問題 No.2771 Personal Space
ユーザー t98slidert98slider
提出日時 2024-06-01 20:57:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 4,076 ms
コンパイル使用メモリ 267,376 KB
実行使用メモリ 36,112 KB
最終ジャッジ日時 2024-06-01 20:58:06
合計ジャッジ時間 11,480 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 135 ms
36,024 KB
testcase_02 AC 130 ms
36,004 KB
testcase_03 AC 130 ms
35,972 KB
testcase_04 AC 128 ms
35,936 KB
testcase_05 AC 132 ms
36,024 KB
testcase_06 AC 152 ms
36,112 KB
testcase_07 AC 78 ms
6,940 KB
testcase_08 AC 52 ms
6,944 KB
testcase_09 AC 73 ms
6,944 KB
testcase_10 AC 111 ms
11,396 KB
testcase_11 AC 117 ms
20,748 KB
testcase_12 AC 115 ms
21,988 KB
testcase_13 AC 57 ms
6,940 KB
testcase_14 AC 72 ms
6,944 KB
testcase_15 AC 88 ms
6,940 KB
testcase_16 AC 89 ms
6,940 KB
testcase_17 AC 97 ms
6,944 KB
testcase_18 AC 74 ms
6,944 KB
testcase_19 AC 70 ms
6,940 KB
testcase_20 AC 144 ms
20,540 KB
testcase_21 AC 121 ms
20,336 KB
testcase_22 AC 119 ms
20,100 KB
testcase_23 AC 142 ms
35,212 KB
testcase_24 AC 119 ms
21,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

using S = array<pair<int,int>, 3>;

pair<int,int> comp(pair<int,int> lhs, pair<int,int> rhs){
    if(lhs.first == rhs.first) {
        return lhs.second < rhs.second ? lhs : rhs;
    }
    return lhs.first > rhs.first ? lhs : rhs;
}

S op(S lhs, S rhs){
    if(lhs[0].first == -1) return rhs;
    if(rhs[0].first == -1) return lhs;
    S tmp;
    tmp[0] = comp(lhs[0], rhs[0]);
    tmp[1] = lhs[1];
    tmp[2] = rhs[2];
    int d = abs(rhs[1].second - lhs[2].second) / 2;
    tmp[0] = comp(tmp[0], make_pair(d, lhs[2].second + d));
    return tmp;
}
S e(){
    pair<int,int> tmp = {-1, -1};
    return S({tmp, tmp, tmp});
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        int n, m;
        cin >> n >> m;
        m--;
        vector<int> ans(n);
        ans[m] = 1;
        atcoder::segtree<S, op, e> seg(n);
        pair<int,int> tmp;
        tmp = make_pair(0, m);
        seg.set(m, S({tmp, tmp, tmp}));
        for(int i = 2; i <= n; i++){
            auto pa = seg.all_prod();
            if(seg.get(0)[0].first != 0){
                int d = pa[1].second;
                pa[0] = comp(pa[0], make_pair(d, 0));
            }
            if(seg.get(n - 1)[0].first != 0){
                int d = (n - 1 - pa[2].second);
                pa[0] = comp(pa[0], make_pair(d, n - 1));
            }
            int c = pa[0].second;
            ans[c] = i;
            tmp = make_pair(0, c);
            seg.set(c, S({tmp, tmp, tmp}));
        }
        cout << ans << '\n';
    }
}
0