cp_library

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

View the Project on GitHub SSRS-cp/cp_library

:heavy_check_mark: test/aoj/dsl/dsl_5_a.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A"
#include <bits/stdc++.h>
using namespace std;
#include "../../../data_structure/sequence/dual_binary_indexed_tree.hpp"
int main(){
  int N, T;
  cin >> N >> T;
  dual_binary_indexed_tree<int> BIT(T, plus<int>(), 0);
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    BIT.add(l, -1);
    BIT.add(r, 1);
  }
  vector<int> S = BIT.get();
  int ans = 0;
  for (int i = 0; i < T; i++){
    ans = max(ans, S[i]);
  }
  cout << ans << endl;
}
#line 1 "test/aoj/dsl/dsl_5_a.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A"
#include <bits/stdc++.h>
using namespace std;
#line 2 "data_structure/sequence/dual_binary_indexed_tree.hpp"
/**
 * @brief 双対 Binary Indexed Tree
*/
template <typename T>
struct dual_binary_indexed_tree{
  int N;
  vector<T> BIT;
  function<T(T, T)> f;
  T E;
  dual_binary_indexed_tree(){
  }
  dual_binary_indexed_tree(int N, function<T(T, T)> f, T E): N(N), BIT(N + 1, E), f(f), E(E){
  }
  dual_binary_indexed_tree(vector<T> &A, function<T(T, T)> f, T E): N(A.size()), BIT(N + 1), f(f), E(E){
    for (int i = 0; i < N; i++){
      BIT[i + 1] = A[i];
    }
  }
  void add(int i, T x){
    while (i > 0){
      BIT[i] = f(BIT[i], x);
      i -= i & -i;
    }
  }
  T operator [](int i){
    i++;
    T ans = E;
    while (i <= N){
      ans = f(ans, BIT[i]);
      i += i & -i;
    }
    return ans;
  }
  vector<T> get(){
    vector<T> ans = BIT;
    for (int i = N - 1; i >= 1; i--){
      if (i + (i & -i) <= N){
        ans[i] = f(ans[i + (i & -i)], ans[i]);
      }
    }
    ans.erase(ans.begin());
    return ans;
  }
};
#line 5 "test/aoj/dsl/dsl_5_a.test.cpp"
int main(){
  int N, T;
  cin >> N >> T;
  dual_binary_indexed_tree<int> BIT(T, plus<int>(), 0);
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    BIT.add(l, -1);
    BIT.add(r, 1);
  }
  vector<int> S = BIT.get();
  int ans = 0;
  for (int i = 0; i < T; i++){
    ans = max(ans, S[i]);
  }
  cout << ans << endl;
}
Back to top page