Advertisement
SorahISA

4-search-result-ranking

Apr 10th, 2023
674
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2. // #pragma GCC target("avx")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. // #define int int64_t
  7. #define double __float80
  8. using pii = pair<int, int>;
  9. template <typename T> using Prior = std::priority_queue<T>;
  10. template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. // #define X first
  13. // #define Y second
  14. #define eb emplace_back
  15. #define ef emplace_front
  16. #define ee emplace
  17. #define pb pop_back
  18. #define pf pop_front
  19. #define ALL(x) begin(x), end(x)
  20. #define RALL(x) rbegin(x), rend(x)
  21. #define SZ(x) ((int)(x).size())
  22.  
  23. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  24. template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
  25. template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
  26.  
  27. template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  28. template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  29.  
  30. void solve() {
  31.     int N, M; cin >> N >> M;
  32.     int K = min(N, 10);
  33.    
  34.     int key_tok = 0;
  35.     map<string, int> keyword;
  36.    
  37.     vector<pair<int, vector<pii>>> hotel(N);
  38.     for (auto &h : hotel) {
  39.         cin >> h.first;
  40.         int sz; cin >> sz;
  41.         h.second.resize(sz);
  42.         for (pii &k : h.second) {
  43.             string key; cin >> key >> k.second;
  44.             if (!keyword.count(key)) keyword[key] = ++key_tok;
  45.             k.first = keyword[key];
  46.         }
  47.     }
  48.     sort(ALL(hotel));
  49.    
  50.     vector<vector<pii>> with_key(key_tok + 1);
  51.     for (int i = 0; i < N; ++i) {
  52.         for (pii k : hotel[i].second) with_key[k.first].eb(i, k.second);
  53.     }
  54.    
  55.     for (int q = 1; q <= M; ++q) {
  56.         vector<pii> score(N);
  57.         for (int i = 0; i < N; ++i) score[i] = {0, hotel[i].first};
  58.        
  59.         int L; cin >> L;
  60.         bool flag = false;
  61.         for (int _L = 0; _L < L; ++_L) {
  62.             string key; cin >> key;
  63.             int key_val = keyword[key];
  64.             for (pii h : with_key[key_val]) {
  65.                 int idx = h.first;
  66.                 int rel = h.second;
  67.                 score[idx].first += -rel; /// store negative score
  68.                 flag = true;
  69.             }
  70.         }
  71.        
  72.         if (!flag) {
  73.             cout << -1 << "\n";
  74.             continue;
  75.         }
  76.        
  77.         nth_element(begin(score), begin(score) + K - 1, end(score));
  78.         sort(begin(score), begin(score) + K);
  79.        
  80.         // for (int i = 0; i < N; ++i) cout << score[i].first << " " << score[i].second << "\n";
  81.         for (int i = 0; i < K; ++i) {
  82.             if (score[i].first == 0) break;
  83.             if (i) cout << " ";
  84.             cout << score[i].second;
  85.         }
  86.         cout << "\n";
  87.     }
  88. }
  89.  
  90. int32_t main() {
  91.     fastIO();
  92.    
  93.     int t = 1; // cin >> t;
  94.     for (int _ = 1; _ <= t; ++_) {
  95.         solve();
  96.     }
  97.    
  98.     return 0;
  99. }
  100.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement