結果
問題 | No.2002 Range Swap Query |
ユーザー |
👑 ![]() |
提出日時 | 2022-07-08 21:29:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 818 ms / 2,000 ms |
コード長 | 1,506 bytes |
コンパイル時間 | 978 ms |
コンパイル使用メモリ | 80,400 KB |
最終ジャッジ日時 | 2025-01-30 05:17:12 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
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--; | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
// 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;}