結果

問題 No.2002 Range Swap Query
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-07-09 03:32:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,092 ms / 2,000 ms
コード長 1,859 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 173,636 KB
実行使用メモリ 13,472 KB
最終ジャッジ日時 2023-08-28 13:22:29
合計ジャッジ時間 11,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 1,055 ms
13,356 KB
testcase_13 AC 1,092 ms
13,408 KB
testcase_14 AC 1,068 ms
13,412 KB
testcase_15 AC 1,044 ms
13,144 KB
testcase_16 AC 135 ms
13,352 KB
testcase_17 AC 438 ms
13,472 KB
testcase_18 AC 162 ms
8,776 KB
testcase_19 AC 395 ms
10,244 KB
testcase_20 AC 111 ms
11,832 KB
testcase_21 AC 100 ms
8,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.07.09 03:32:04
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.04.30 03:39:29
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int logn = 20; 
constexpr int maxn = 1 << logn;

ll hilbertorder(int x, int y) {
    ll d = 0;
    for (int s = 1<<logn-1; s; s >>= 1) {
        bool rx = x & s, ry = y & s;
        d = d << 2 | rx * 3 ^ static_cast<int>(ry);
        if (ry) continue;
		if (rx) {
			x = maxn - x;
			y = maxn - y;
		}
		swap(x, y);
    }
    return d;
}

int main() {
    int n,k,q;cin >> n >> k >> q;
    vector<int> a(k),b(k),l(q),r(q),x(q),idx(q),p(n),ip(n),ans(q);
    vector<ll> ord(q);
    int count = 0, now_l = 0, now_r = 0;
    for (int i = 0; i < k; i++) { scanf("%d %d",&a[i],&b[i]); a[i]--; b[i]--; }
    for (int i = 0; i < q; i++) { scanf("%d %d %d",&l[i], &r[i], &x[i]); l[i]--; x[i]--; }
    for (int i = 0; i < q; i++) { ord[i] = hilbertorder(l[i],r[i]); }
    iota(p.begin(), p.end(),0);
    iota(ip.begin(), ip.end(),0);
    iota(idx.begin(), idx.end(),0);
    sort(idx.begin(), idx.end(), [&](int a,int b) { return ord[a] < ord[b]; });
    auto swapl = [&](int x) {
        p[ip[a[x]]] = b[x];
        p[ip[b[x]]] = a[x];
        swap(ip[a[x]],ip[b[x]]);
    };
    auto swapr = [&](int x) {
        ip[p[a[x]]] = b[x];
        ip[p[b[x]]] = a[x];
        swap(p[a[x]],p[b[x]]);
    };
    for (int i = 0; i < q; i++) {
        while(now_l > l[idx[i]]) swapl(--now_l);
        while(now_r < r[idx[i]]) swapr(now_r++);
        while(now_l < l[idx[i]]) swapl(now_l++);
        while(now_r > r[idx[i]]) swapr(--now_r);
        ans[idx[i]] = p[x[idx[i]]];
    }
    for (int i = 0; i < q; i++) printf("%d\n",ans[i]+1);
    return 0;
}
0