用 pb_ds 库平衡树竟然 WA 了。。。
查看原帖
用 pb_ds 库平衡树竟然 WA 了。。。
93259
Zirnc楼主2022/1/24 21:37

无话可说了属于是

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
__gnu_pbds ::tree<int, __gnu_pbds::null_type, less<int>,
                  __gnu_pbds::rb_tree_tag,
                  __gnu_pbds::tree_order_statistics_node_update>
    tre;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int op, x;
    scanf("%d%d", &op, &x);
    if (op == 1) {
      tre.insert(x);
    } else if (op == 2) {
      tre.erase(tre.lower_bound(x));
    } else if (op == 3) {
      printf("%d\n", tre.order_of_key(x) + 1);
    } else if (op == 4) {
      printf("%d\n", *(tre.find_by_order(x - 1)));
    } else if (op == 5) {
      auto it = tre.lower_bound(x);
      it--;
      printf("%d\n", *it);
    } else if (op == 6) {
      auto it = tre.upper_bound(x);
      printf("%d\n", *it);
    }
  }

  return 0;
}
2022/1/24 21:37
加载中...