#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; using P = pair; int prev_pos[1000000][20]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k, q; cin >> n >> k >> q; vector a(k), b(k); for(int i = 0; i < k; i++){ cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector> operations(n); vector

ps; for(int i = 0; i < k; i++){ operations[a[i]].push_back(i); operations[b[i]].push_back(i); ps.push_back(P(i, a[i])); ps.push_back(P(i, b[i])); ps.push_back(P(i+1, a[i])); ps.push_back(P(i+1, b[i])); } auto cp = Compress

(ps); int m = cp.size(); for(int i = 0; i < m; i++){ for(int j = 0; j < 20; j++){ prev_pos[i][j] = -1; } } for(int i = 0; i < k; i++){ prev_pos[cp[P(i+1, a[i])]][0] = cp[P(i, b[i])]; prev_pos[cp[P(i+1, b[i])]][0] = cp[P(i, a[i])]; auto p = lower_bound(operations[a[i]].begin(), operations[a[i]].end(), i); if(p != operations[a[i]].begin()){ int idx = *prev(p); if(idx == i-1){ if(a[i-1] == a[i]) prev_pos[cp[P(i, a[i])]][0] = cp[P(i-1, b[i-1])]; else prev_pos[cp[P(i, a[i])]][0] = cp[P(i-1, a[i-1])]; }else{ prev_pos[cp[P(i, a[i])]][0] = cp[P(idx+1, a[i])]; } } p = lower_bound(operations[b[i]].begin(), operations[b[i]].end(), i); if(p != operations[b[i]].begin()){ int idx = *prev(p); if(idx == i-1){ if(a[i-1] == b[i]) prev_pos[cp[P(i, b[i])]][0] = cp[P(i-1, b[i-1])]; else prev_pos[cp[P(i, b[i])]][0] = cp[P(i-1, a[i-1])]; }else{ prev_pos[cp[P(i, b[i])]][0] = cp[P(idx+1, b[i])]; } } } for(int j = 0; j+1 < 20; j++){ for(int i = 0; i < m; i++){ if(prev_pos[i][j] == -1) continue; prev_pos[i][j+1] = prev_pos[prev_pos[i][j]][j]; } } auto go = [&](int idx, int cnt){ for(int j = 0; j < 20; j++){ if(cnt&(1<> l >> r >> x; l--; r--; x--; if(operations[x].empty()){ cout << x+1 << endl; continue; } auto p = upper_bound(operations[x].begin(), operations[x].end(), r); if(p == operations[x].begin()){ cout << x+1 << endl; continue; } int ope_idx = *prev(p); int idx = cp[P(ope_idx+1, x)]; int small = 0, large = 2*k; while(large-small > 1){ int c = (small+large)/2; auto i = go(idx, c); if(i == -1) { large = c; continue; } int array_idx = cp.data[i].first; if(array_idx < l) large = c; else small = c; } auto i = go(idx, small); cout << cp.data[i].second+1 << endl; } }