Language: C++

/*
g++ -std=c++11 -o2 -Wall ABC106D.cpp -o ./out/ABC106D.out
./out/ABC106D.out
*/

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

typedef long long ll;
typedef ll Int;

constexpr Int N = 512;

Int al[N];
Int ar[N];

constexpr Int INF = 1e18;

Int tree[2 * N];

auto query = [&N, &tree](int a, int b) -> Int {
     a += N;
     b += N;
     Int s = 0;
     while (a <= b) {
         if (a % 2 == 1) {
             s += tree[a++];
         }
         if (b % 2 == 0) {
             s += tree[b--];
         }
         a /= 2;
         b /= 2;
     }
     return s;
 };

 auto update = [&N, &tree](int k, int x) -> void {
     k += N;
     tree[k] += x;
     for (k /= 2; k >= 1; k /= 2) {
         tree[k] = tree[2 * k] + tree[2 * k + 1];
     }
 };

int main(){
  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);

  fill(tree, tree + 2 * N, 0);

  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      update(j, 1);
    }
  }
  for (int i = 0; i < q; ++i) {
    int ans = 0;
    int p1, p2;
    cin >> p1 >> p2;
    for (int j = p1; j <= p2; ++j) {
      Int a = query(j, j);
      ans = max(ans, a);
    }
    cout << ans << "\n";
  }
}


Compiler output:
a.cc:21:16: warning: capture of variable 'N' with non-automatic storage duration
   21 | auto query = [&N, &tree](int a, int b) -> Int {
      |                ^
a.cc:12:15: note: 'constexpr const Int N' declared here
   12 | constexpr Int N = 512;
      |               ^
a.cc:21:20: warning: capture of variable 'tree' with non-automatic storage duration
   21 | auto query = [&N, &tree](int a, int b) -> Int {
      |                    ^~~~
a.cc:19:5: note: 'Int tree [1024]' declared here
   19 | Int tree[2 * N];
      |     ^~~~
a.cc:38:18: warning: capture of variable 'N' with non-automatic storage duration
   38 |  auto update = [&N, &tree](int k, int x) -> void {
      |                  ^
a.cc:12:15: note: 'constexpr const Int N' declared here
   12 | constexpr Int N = 512;
      |               ^
a.cc:38:22: warning: capture of variable 'tree' with non-automatic storage duration
   38 |  auto update = [&N, &tree](int k, int x) -> void {
      |                      ^~~~
a.cc:19:5: note: 'Int tree [1024]' declared here
   19 | Int tree[2 * N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:68:16: error: no matching function for call to 'max(int&, Int&)'
   68 |       ans = max(ans, a);
      |             ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:68:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'Int' {aka 'long long int'})
   68 |       ans = max(ans, a);
      |             ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:68:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |       ans = max(ans, a);
      |             ~~~^~~~~~~~