結果
問題 | No.1558 Derby Live |
ユーザー | magsta |
提出日時 | 2021-05-21 16:01:16 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,210 bytes |
コンパイル時間 | 7,326 ms |
コンパイル使用メモリ | 227,508 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-25 08:02:26 |
合計ジャッジ時間 | 8,812 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
ソースコード
#include <iostream> #include <vector> #include "testlib.h" using namespace std; template <typename T> struct SegTree { const T INF = numeric_limits<T>::max(); int n, m; vector<vector<T>> dat; SegTree(int n_, int m_) : dat(n_ * 4, vector<T>(m_, 0)) { int x = 1; while (n_ > x) { x *= 2; } n = x; m = m_; } void init() { for (int i = 0; i < 2 * n - 1; i++) { for (int j = 0; j < m; j++) { dat[i][j] = j; } } } void update(int i, vector<T> x) { i += n - 1; for (int j = 0; j < m; j++) dat[i][j] = x[j]; while (i > 0) { i = (i - 1) / 2; for (int j = 0; j < m; j++) dat[i][j] = dat[i * 2 + 2][dat[i * 2 + 1][j]]; } } vector<T> query(int a, int b) { return query_sub(a, b, 0, 0, n); } vector<T> query_sub(int a, int b, int k, int l, int r) { vector<T> x(m); if (r <= a || b <= l) { for (int i = 0; i < m; i++) x[i] = i; } else if (a <= l && r <= b) { for (int i = 0; i < m; i++) x[i] = dat[k][i]; } else { vector<T> vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); vector<T> vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); for (int i = 0; i < m; i++) x[i] = vr[vl[i]]; } return x; } }; int main() { registerValidation(); long long N = inf.readLong((long long)2, (long long)18, "N"); inf.readSpace(); long long M = inf.readLong((long long)2, (long long)10000, "M"); inf.readSpace(); long long Q = inf.readLong((long long)2, (long long)50000, "Q"); inf.readEoln(); SegTree<long long> Seg(M, N); Seg.init(); for (int i = 0; i < Q; i++) { int com = inf.readInt(1, 3); if (com == 1) { long long B = inf.readLong((long long)1, M, "B"); vector<long long> P(N); for (int j = 0; j < N; j++) { inf.readSpace(); P[j] = inf.readLong((long long)1, N, "P"); } for (int j = 0; j < N; j++) P[j]--; vector<bool> flag(N, false); for (int j = 0; j < N; j++) { if (flag[P[j]]) cout << -1 << endl; else flag[P[j]] = true; } Seg.update(B - 1, P); } if (com == 2) { inf.readSpace(); long long S = inf.readLong((long long)1, M, "S"); auto x = Seg.query(0, S); vector<long long> y(N); for (int j = 0; j < N; j++) y[x[j]] = j; cout << y[0] + 1; for (int j = 1; j < N; j++) cout << " " << y[j] + 1; cout << endl; } if (com == 3) { inf.readSpace(); long long a = inf.readLong((long long)1, M, "L"); inf.readSpace(); long long b = inf.readLong(a, M, "R"); auto x = Seg.query(a - 1, b); long long count = 0; for (int j = 0; j < N; j++) count += abs(x[j] - j); cout << count << endl; } inf.readEoln(); } inf.readEof(); }