結果

問題 No.1558 Derby Live
ユーザー rtyurtyu
提出日時 2021-07-12 15:07:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,036 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 79,016 KB
実行使用メモリ 7,428 KB
最終ジャッジ日時 2023-09-14 20:35:06
合計ジャッジ時間 8,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
7,192 KB
testcase_01 AC 156 ms
7,200 KB
testcase_02 AC 3 ms
4,512 KB
testcase_03 AC 128 ms
4,480 KB
testcase_04 AC 60 ms
5,156 KB
testcase_05 AC 63 ms
4,836 KB
testcase_06 AC 135 ms
5,132 KB
testcase_07 AC 6 ms
5,092 KB
testcase_08 AC 116 ms
5,252 KB
testcase_09 AC 118 ms
5,248 KB
testcase_10 AC 139 ms
5,884 KB
testcase_11 AC 141 ms
5,908 KB
testcase_12 AC 143 ms
5,880 KB
testcase_13 AC 149 ms
5,964 KB
testcase_14 AC 152 ms
6,084 KB
testcase_15 AC 157 ms
6,120 KB
testcase_16 AC 166 ms
5,928 KB
testcase_17 AC 166 ms
5,960 KB
testcase_18 AC 187 ms
7,292 KB
testcase_19 AC 193 ms
7,132 KB
testcase_20 AC 194 ms
7,384 KB
testcase_21 AC 188 ms
7,384 KB
testcase_22 AC 192 ms
7,168 KB
testcase_23 AC 195 ms
7,368 KB
testcase_24 AC 188 ms
7,428 KB
testcase_25 AC 189 ms
7,148 KB
testcase_26 AC 198 ms
7,160 KB
testcase_27 AC 190 ms
7,128 KB
testcase_28 AC 192 ms
7,292 KB
testcase_29 AC 193 ms
7,184 KB
testcase_30 AC 189 ms
7,124 KB
testcase_31 AC 192 ms
7,252 KB
testcase_32 AC 194 ms
7,136 KB
testcase_33 AC 3 ms
4,432 KB
testcase_34 AC 2 ms
4,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int pn, a[29];
vector<int> st[40009], iv;

void init(int tn, int s, int e)
{
    for (int i = 0; i <= pn; i++)
        st[tn].push_back(i);
    if (s != e) {
        int md = (s + e) / 2;
        init(tn * 2, s, md);
        init(tn * 2 + 1, md + 1, e);
    }
}

void update(int tn, int s, int e, int p)
{
    if (s == e) {
        for (int i = 1; i <= pn; i++)
            st[tn][i] = a[i];
        return;
    }
    int md = (s + e) / 2;
    if (p <= md) update(tn * 2, s, md, p);
    else update(tn * 2 + 1, md + 1, e, p);
    for (int i = 1; i <= pn; i++)
        st[tn][i] = st[tn * 2 + 1][st[tn * 2][i]];
}

vector<int> qry(int tn, int s, int e, int ts, int te)
{
    if (e < ts || te < s) return iv;
    if (ts <= s && e <= te) return st[tn];
    int md = (s + e) / 2;
    vector<int> lv = qry(tn * 2, s, md, ts, te), rv = qry(tn * 2 + 1, md + 1, e, ts, te), tv;
    tv.push_back(0);
    for (int i = 1; i <= pn; i++)
        tv.push_back(rv[lv[i]]);
    return tv;

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q; cin >> pn >> n >> q;
    for (int i = 0; i <= pn; i++)
        iv.push_back(i);
    init(1, 1, n);
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) {
            int d; cin >> d;
            for (int i = 1; i <= pn; i++)
                cin >> a[i];
            update(1, 1, n, d);
        }
        else if (t == 2) {
            int s; cin >> s;
            vector<int> ans = qry(1, 1, n, 1, s);
            for (int i = 1; i <= pn; i++)
                a[ans[i]] = i;
            for (int i = 1; i <= pn; i++)
                cout << a[i] << " ";
            cout << '\n';
        }
        else {
            int l, r; cin >> l >> r;
            vector<int> ans = qry(1, 1, n, l, r);
            int s = 0;
            for (int i = 1; i <= pn; i++) 
                s += abs(i - ans[i]);
            cout << s << '\n';
        }
    }
    return 0;
}
0