fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define i(n) scanf("%d",&n);
  5. typedef multimap<pair<int,int>,pair<int,int> > mmap;
  6.  
  7. int main(){
  8. int N,M;
  9. i(N); i(M);
  10. mmap MP;
  11. int id, attr, val, pty;
  12.  
  13. for(int i = 0; i < N; ++i){
  14. i(id); i(attr); i(val); i(pty);
  15. MP.insert({make_pair(id,attr),make_pair(val,pty)});
  16. }
  17.  
  18. pair<mmap::iterator, mmap::iterator> ppp;
  19.  
  20. for(int i = 0; i < M; ++i){
  21. i(id); i(attr);
  22. ppp = MP.equal_range({id,attr});
  23.  
  24. int ans;
  25. int pr = -1;
  26. for(mmap::iterator it = ppp.first; it != ppp.second; it++){
  27. int cval = (*it).second.first;
  28. int cpr = (*it).second.second;
  29. if(cpr >= pr){
  30. ans = cval;
  31. pr = cpr;
  32. }
  33. }
  34. printf("%d\n",ans);
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3432KB
stdin
3 1
22 1 200 2
22 1 300 2
22 1 100 1
22 1
stdout
300