Comments

handsome solution! now use less_equal also work fine, thanks

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>   // Common file
#include <ext/pb_ds/tree_policy.hpp>       // Including tree_order_statistics_node_update
using namespace __gnu_pbds;

template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> 
using MultiTree = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;


/*
If using MultiTree:
   Ranking of x:                                                mt.order_of_key(x) + 1
   Find the number with rank idx:                               *mt.find_by_order(idx)
   To delete only one of multiple identical numbers:            mt.erase(st.upper_bound(x));
   Predecessor is defined as the largest number less than x:    *--mt.upper_bound(x)
   Successor is defined as the smallest number greater than x:  *mt.lower_bound(x)
*/

int main() {
   MultiTree<int> mt;
   int n = 0;
   cin >> n;
   while (n--) {
      int op, x;
      cin >> op >> x;
      if (op == 1) { // insert 
         mt.insert(x);
      }
      if (op == 2) { // erase 
         mt.erase(mt.upper_bound(x));
      }
      if (op == 3) { // rank
         cout << mt.order_of_key(x) + 1 << endl;
      }
      if (op == 4) { // rank val
         cout << *mt.find_by_order(x - 1) << endl;
      }
      if (op == 5) { // pre
         cout << *--mt.upper_bound(x) << endl;
      }
      if (op == 6) { // suf
         cout << *mt.lower_bound(x) << endl;
      }
   }
   return 0;
}

Allocating an array space and initializing it is always O(n). The correct way to write it should be your global writing method, or.

#include <xxx>
int solve() {
  vector<vector<int>> yourvector(n, vector<int>(m,0))
  fution<> useYourVector() -> bool {
    cleardata()
    then use vector
  };
  return; 
}

int main() {
 solve()
}

because of the code logic is TLE. Opening an array is generally of a linear complexity rather than O(1). It has nothing to do with being global or not. When n and m are large enough, your tle code is equivalent to doing an additional traversal each time.

why problem use priority_queue wrong? AC x6, WA x11

auto main() -> int32_t {
    int n = 0;
    cin >> n;

    vector<array<int, 3>> a(n);
    for (int i = 0; i < n; i++) {
        a[i][0] = i + 1;
        cin >> a[i][1] >> a[i][2];
    }

    sort(a.begin(), a.end(), [](auto& x, auto& y) { return x[1] < y[1]; });

    function<bool(pair<int, int>&, pair<int, int>&)> maxPQCmp =
        [](pair<int, int>& x, pair<int, int>& y) {
            return x.first < y.first;};    
    priority_queue<pair<int, int>, vector<pair<int, int>>,function<bool(pair<int, int>&, pair<int, int>&)>>
        maxPQ(maxPQCmp);

    vector<bool> st(n + 1, true);

    for (int i = 0; i < n; i++) {
        if (maxPQ.size() and maxPQ.top().first >= a[i][2]) {
            auto t = maxPQ.top();
            maxPQ.pop();
            st[t.second] = false;
        }
        maxPQ.push({a[i][2], a[i][0]});
    }

    int haha = 0;
    for (int i = 1; i <= n; i++) {
        if (st[i] == true) haha += 1;
    }

    cout << haha << endl;
    for (int i = 1; i <= n;i++) {
        if (st[i] == true) {
            cout << i << ' ';
        }
    }

    return 0;
}