Submission #496709

# Submission time Handle Problem Language Result Execution time Memory
496709 2021-12-22T02:22:29 Z Dan4Life Regions (IOI09_regions) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int n,r,q,cnt=1, a[maxn], st[maxn], en[maxn], B[maxn];
vector<int> adj[maxn], v[25001];
void dfs(int s, int p = -1)
{
    st[s] = cnt++;
    for(auto u : adj[s])
        if(u!=p) dfs(u,s);
    en[s] = cnt-1;
}

int32_t main()
{
    cin >> n >> r >> q >> a[1];
    for(int i = 2; i <= n; i++)
    {
        int x; cin >> x >> a[i];
        adj[x].push_back(i);
    }
    dfs(1); for(int i = 1; i <= n; i++) B[st[i]]=i;
    for(int i = 1; i <= n; i++) v[a[B[i]]].push_back(st[B[i]]);
    while(q--)
    {
        int a, b, ans = 0; cin >> a >> b;
        for(auto u : v[a]){
            int l = st[B[u]], r = en[B[u]];
            auto itr = upper_bound(v[b].begin(), v[b].end(), r)-v[b].begin();
            auto itr2 = upper_bound(v[b].begin(), v[b].end(), l)-v[b].begin();
            if(itr) itr--, ans+=max(itr-itr2+1, 0);
        }
        cout << ans << endl;
    }
}

Compilation message

regions.cpp: In function 'int32_t main()':
regions.cpp:31:50: error: no matching function for call to 'max(long int, int)'
   31 |             if(itr) itr--, ans+=max(itr-itr2+1, 0);
      |                                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from regions.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
regions.cpp:31:50: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   31 |             if(itr) itr--, ans+=max(itr-itr2+1, 0);
      |                                                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from regions.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
regions.cpp:31:50: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   31 |             if(itr) itr--, ans+=max(itr-itr2+1, 0);
      |                                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from regions.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
regions.cpp:31:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   31 |             if(itr) itr--, ans+=max(itr-itr2+1, 0);
      |                                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from regions.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
regions.cpp:31:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   31 |             if(itr) itr--, ans+=max(itr-itr2+1, 0);
      |                                                  ^