#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; int P[400000],WP[400000],A[200000],B[200000],ans[200000]; tuple query[200000]; int sqr; bool compare(tuple &a,tuple &b){ if(get<0>(a)/sqr == get<0>(b)/sqr) return (get<1>(a)(b))^(get<0>(a)/sqr%2); else return get<0>(a)/sqr < get<0>(b)/sqr; } int main(){ cin.tie(0);ios::sync_with_stdio(false); int N,K,Q;cin >> N >> K >> Q; for(int i=0;i> A[i] >> B[i];A[i]--;B[i]--; } for(int i=0;i> l >> r >> x; query[i] = make_tuple(l-1,r,x-1,i); } sqr = sqrt(N); sort(query,query+Q,compare); for(int i=0;i l){ litr--; swap(WP[A[litr]],WP[B[litr]]); swap(P[WP[A[litr]]],P[WP[B[litr]]]); } while(ritr > r){ ritr--; swap(P[A[ritr]],P[B[ritr]]); swap(WP[P[A[ritr]]],WP[P[B[ritr]]]); } while(litr < l){ swap(WP[A[litr]],WP[B[litr]]); swap(P[WP[A[litr]]],P[WP[B[litr]]]); litr++; } ans[id] = P[x]+1; } for(int i=0;i