Untitled
unknown
c_cpp
a year ago
1.3 kB
6
Indexable
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int tt, tc;
void solve() {
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, vector<int>>> rankings(m);
for (auto& [u, V] : rankings) {
cin >> u;
V = vector<int>(n + 1);
for (int i = 1; i <= n; i++) cin >> V[i];
vector<int> inv(n + 1);
for (int i = 1; i <= n; i++) inv[V[i]] = i;
V = inv;
}
vector<int> pos(m);
iota(pos.begin(), pos.end(), 0);
sort(pos.begin(), pos.end(), [&](int i, int j) {
return rankings[i].first < rankings[j].first;
});
vector<int> inv(m);
for (int i = 0; i < m; i++) inv[pos[i]] = i;
vector<int> ss(m);
for (int i = 0; i < m; i++) ss[i] = rankings[pos[i]].first;
while (q--) {
int x, y, t;
cin >> x >> y >> t;
int idx = upper_bound(ss.begin(), ss.end(), t) - ss.begin() - 1;
if (idx < 0) {
cout << min(x, y) << "\n";
continue;
}
int rank_idx = inv[idx];
auto& V = rankings[rank_idx].second;
int where_x = V[x];
int where_y = V[y];
cout << (where_x < where_y ? x : y) << "\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
tt = 1, tc = 1;
// cin >> tt;
while (tt--) {
solve();
tc++;
}
}Editor is loading...
Leave a Comment