結果

問題 No.2002 Range Swap Query
ユーザー 👑 NachiaNachia
提出日時 2022-07-08 21:28:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 81,448 KB
実行使用メモリ 10,100 KB
最終ジャッジ日時 2023-08-27 20:50:37
合計ジャッジ時間 9,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,008 KB
testcase_01 AC 2 ms
4,944 KB
testcase_02 AC 2 ms
4,952 KB
testcase_03 AC 2 ms
4,944 KB
testcase_04 AC 2 ms
5,008 KB
testcase_05 AC 2 ms
4,944 KB
testcase_06 AC 2 ms
4,948 KB
testcase_07 AC 1 ms
4,948 KB
testcase_08 AC 4 ms
5,012 KB
testcase_09 AC 5 ms
4,944 KB
testcase_10 AC 2 ms
4,948 KB
testcase_11 AC 5 ms
5,008 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

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[100000];
UL T[100000];
UL rT[100000];
UL A[100000][2];
vector<Query> Que[2][300];
UL L,R;
UL ans[100000];

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*300/K].push_back(Query{l,r,x,q});
 }
 rep(c,2) rep(i,300) 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,300){
   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