zoukankan      html  css  js  c++  java
  • [学习笔记] pd_ds黑科技

    https://www.cnblogs.com/jiqimin/p/11226809.html

    丢个链接,跑路

    // Author: wlzhouzhuan
    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #include <bits/stdc++.h>
    #include <ext/pb_ds/priority_queue.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    
    #define ll long long
    #define ull unsigned long long
    #define rint register int
    #define rep(i, l, r) for (rint i = l; i <= r; i++)
    #define per(i, l, r) for (rint i = l; i >= r; i--)
    #define mset(s, _) memset(s, _, sizeof(s))
    #define pb push_back
    #define pii pair <int, int>
    #define mp(a, b) make_pair(a, b)
    
    inline int read() {
      int x = 0, neg = 1; char op = getchar();
      while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
      while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
      return neg * x;
    }
    inline void print(int x) {
      if (x < 0) { putchar('-'); x = -x; }
      if (x >= 10) print(x / 10);
      putchar(x % 10 + '0');
    }
    
    const int N = 105;
    #define it_min __gnu_pbds::priority_queue <pii, greater <pii>, pairing_heap_tag>::point_const_iterator
    #define it_max __gnu_pbds::priority_queue <pii, less <pii>, pairing_heap_tag>::point_const_iterator
    __gnu_pbds::priority_queue <pii, greater <pii>, pairing_heap_tag> pq_min[N];
    __gnu_pbds::priority_queue <pii, less <pii>, pairing_heap_tag> pq_max[N];
    unordered_map <int, it_min> fa;
    unordered_map <int, it_max> fb;
    int n, m;
    
    int main() {
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      cin >> n >> m;
      for (rint i = 1; i <= m; i++) {
        int opt;
        cin >> opt;
        if (opt == 1) {
          int x, y;
          cin >> x >> y;
          it_min v1 = pq_min[x].push({y, i}); fa[i] = v1;
          it_max v2 = pq_max[x].push({y, i}); fb[i] = v2;
        } else if (opt == 2) {
          int x;
          cin >> x;
          if (pq_min[x].empty()) cout << "-1
    ";
          else {
            pii ans = pq_min[x].top(); 
            cout << ans.first << '
    ';
            pq_min[x].pop();
            pq_max[x].erase(fb[ans.second]);
          }
        } else if (opt == 3) {
          int x;
          cin >> x;
          if (pq_max[x].empty()) cout << "-1
    ";
          else {
            pii ans = pq_max[x].top();
            cout << ans.first << '
    ';
            pq_max[x].pop();
            pq_min[x].erase(fa[ans.second]);
          }
        } else {
          int x, y;
          cin >> x >> y;
          pq_min[y].join(pq_min[x]);
          pq_max[y].join(pq_max[x]);
        }
      }  
      return 0;
    }
    
  • 相关阅读:
    January 25th, 2018 Week 04th Thursday
    January 24th, 2018 Week 04th Wednesday
    January 23rd, 2018 Week 04th Tuesday
    January 22nd, 2018 Week 04th Monday
    January 21st, 2018 Week 3rd Sunday
    January 20th, 2018 Week 3rd Saturday
    January 19th, 2018 Week 3rd Friday
    January 18th, 2018 Week 03rd Thursday
    January 17th, 2018 Week 03rd Wednesday
    January 16th, 2018 Week 03rd Tuesday
  • 原文地址:https://www.cnblogs.com/wlzhouzhuan/p/12797021.html
Copyright © 2011-2022 走看看