結果

問題 No.2002 Range Swap Query
ユーザー 👑 NachiaNachia
提出日時 2022-07-08 21:29:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 772 ms / 2,000 ms
コード長 1,506 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 16,932 KB
最終ジャッジ日時 2023-08-27 20:51:22
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,652 KB
testcase_01 AC 2 ms
7,708 KB
testcase_02 AC 3 ms
7,652 KB
testcase_03 AC 2 ms
7,716 KB
testcase_04 AC 2 ms
7,580 KB
testcase_05 AC 2 ms
7,880 KB
testcase_06 AC 2 ms
7,664 KB
testcase_07 AC 2 ms
7,716 KB
testcase_08 AC 6 ms
7,800 KB
testcase_09 AC 6 ms
7,852 KB
testcase_10 AC 3 ms
7,664 KB
testcase_11 AC 5 ms
7,920 KB
testcase_12 AC 767 ms
16,752 KB
testcase_13 AC 772 ms
16,876 KB
testcase_14 AC 752 ms
16,932 KB
testcase_15 AC 716 ms
16,452 KB
testcase_16 AC 128 ms
15,032 KB
testcase_17 AC 381 ms
16,744 KB
testcase_18 AC 114 ms
13,240 KB
testcase_19 AC 354 ms
15,436 KB
testcase_20 AC 86 ms
13,416 KB
testcase_21 AC 75 ms
11,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4683042#1

//#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using UL=unsigned int;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

struct Query{ UL l,r,x,i; };
bool cmp_r(const Query& l,const Query& r){ return l.r>r.r; }

UL N,K,Q;
UL S[400000];
UL T[400000];
UL rT[400000];
UL A[400000][2];
vector<Query> Que[2][700];
UL L,R;
UL ans[400000];

void exe(UL l, UL r){
 for(int p=R; p<r; p++) swap(S[A[p][0]],S[A[p][1]]);
 for(int p=R; p>r; p--) swap(S[A[p-1][0]],S[A[p-1][1]]);
 for(int p=L; p<l; p++){
  swap(rT[T[A[p][0]]],rT[T[A[p][1]]]);
  swap(T[A[p][0]],T[A[p][1]]);
 }
 for(int p=L; p>l; p--){
  swap(rT[T[A[p-1][0]]],rT[T[A[p-1][1]]]);
  swap(T[A[p-1][0]],T[A[p-1][1]]);
 }
 L=l; R=r;
}

int main(){
 scanf("%u%u%u",&N,&K,&Q);
 L=R=0;
 rep(i,K) rep(j,2){ scanf("%u",&A[i][j]); A[i][j]--; }
 rep(q,Q){
  //UL c,l,r,x; scanf("%u%u%u%u",&c,&l,&r,&x); c--; l--; x--;
  UL c=1,l,r,x; scanf("%u%u%u",&l,&r,&x); c--; l--; x--;
  Que[c][l*700/K].push_back(Query{l,r,x,q});
 }
 rep(c,2) rep(i,700) sort(Que[c][i].begin(),Que[c][i].end(),cmp_r);
 rep(c,2){
  rep(i,N)S[i]=i;
  rep(i,N)T[i]=i;
  rep(i,N)rT[i]=i;
  L=R=0;
  rep(i,700){
   for(Query& q:Que[c][i]){
    if(c==0){
     exe(q.l,q.r);
     ans[q.i]=rT[S[q.x]]+1;
    }
    else {
     exe(q.r,q.l);
     ans[q.i]=rT[S[q.x]]+1;
    }
   }
  }
 }
 rep(i,Q) printf("%u\n",ans[i]);
 return 0;
}
0