結果

問題 No.2002 Range Swap Query
ユーザー 👑 NachiaNachia
提出日時 2022-07-08 21:28:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 80,956 KB
最終ジャッジ日時 2025-01-30 05:17:00
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 RE * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:7: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |  scanf("%u%u%u",&N,&K,&Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:43:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |  rep(i,K) rep(j,2){ scanf("%u",&A[i][j]); A[i][j]--; }
      |                     ~~~~~^~~~~~~~~~~~~~~
main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |   UL c=1,l,r,x; scanf("%u%u%u",&l,&r,&x); c--; l--; x--;
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

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