competitive-programming-templates

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Misuki743/competitive-programming-templates

:warning: ds_problem/arg_sort_Mo.cpp

Code

template<integral T>
auto arg_sort_Mo(vc<pair<T, T>> &v) {
  int n = 1;
  for(auto &[x, y] : v) chmax(n, max(x, y));
  int b = ceil_div(n, (int)kth_root(ssize(v) + 1, 2));
  return pair(
    arg_sort(v, [b](const pii &pr) {
      auto [x, y] = pr;
      return pii(x / b, x / b % 2 == 0 ? y : -y);
    }), b);
}
#line 1 "ds_problem/arg_sort_Mo.cpp"
template<integral T>
auto arg_sort_Mo(vc<pair<T, T>> &v) {
  int n = 1;
  for(auto &[x, y] : v) chmax(n, max(x, y));
  int b = ceil_div(n, (int)kth_root(ssize(v) + 1, 2));
  return pair(
    arg_sort(v, [b](const pii &pr) {
      auto [x, y] = pr;
      return pii(x / b, x / b % 2 == 0 ? y : -y);
    }), b);
}
Back to top page