BOSS - Ai là sếp
Tác giả: khuc_tuan
Ngôn ngữ: C++
#include <iostream>
#include <set>
#include <map>
using namespace std;
int n, m;
pair<pair<int,int>, int> a[33000];
int sep[33000], solinh[33000];
struct cmp {
bool operator()(int u, int v) {
if(a[u].first.second != a[v].first.second) return a[u].first.second < a[v].first.second;
else return u < v;
}
};
int main() {
int st;
scanf("%d", &st);
for(int kk=0;kk<st;++kk) {
scanf("%d%d", &n, &m);
for(int i=0;i<n;++i)
scanf("%d%d%d", &a[i].second, &a[i].first.second, &a[i].first.first);
sort( a, a+n);
set<int, cmp> se;
map<int,int> ma;
for(int i=0;i<n;++i) ma[a[i].second] = i;
for(int i=n-1;i>=0;--i) {
set<int, cmp> :: iterator p = se.upper_bound(i);
if(p==se.end()) sep[i] = -1;
else sep[i] = * p;
se.insert(i);
}
memset( solinh, 0, sizeof(solinh));
for(int i=0;i<n;++i)
if(sep[i]!=-1) solinh[sep[i]] += solinh[i] + 1;
for(int i=0;i<m;++i) {
int sohieu;
scanf("%d", &sohieu);
int id = ma[sohieu];
printf("%d ", sep[id]==-1 ? 0 : (a[sep[id]].second));
printf("%d\n", solinh[id]);
}
}
return 0;
}