結果

問題 No.1558 Derby Live
ユーザー rtyurtyu
提出日時 2021-07-12 15:06:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,031 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 78,720 KB
実行使用メモリ 7,292 KB
最終ジャッジ日時 2023-09-14 20:34:56
合計ジャッジ時間 10,475 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
4,376 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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, 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