Submission #649958

# Submission time Handle Problem Language Result Execution time Memory
649958 2022-10-11T18:05:28 Z enerelt14 Cats or Dogs (JOI18_catdog) C++14
Compilation error
0 ms 0 KB
#include "catdog.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int MX=1e5+5;
int n, sz[MX], par[MX], num[MX];
int hldpar[MX], pos[MX], st[MX];
vetcor<int>adj[MX];
void dfs(int u, int pre){
    sz[u]=1;
    par[u]=pre;
    for (int i=0;i<adj[u].size();i++){
        int v=adj[u][i];
        if (v==pre)continue;
        dfs(v);
        sz[u]+=sz[v];
    }
}
void hld(int u, int pre){
    num[u]++;
    pos[u]=num[pre];
    hldpar[u]=pre;
    for (int i=0;i<adj[u].size();i++){
        int v=adj[u][i];
        if (v==par[u])continue;
        if (sz[v]*2>=sz[u])hld(v, pre);
        else hld(v, v);
    }
}
struct node{
    int a00, a01, a10, a11;
    friend node operator + (const node& a, cons node& b){
        node c;
        c.a00=min(a.a00+b.a00, a.a01+b.a10);
        c.a01=min(a.a00+b.a01, a.a01+b.a11);
        c.a10=min(a.a10+b.a00, a.a11+b.a10);
        c.a11=min(a.a10+b.a01, a.a11+b.a11);
        return c;
    }
};
struct segtree{
    int s;
    vector<node>cost;
    segtree(int n){
        while(s<n)s*=2;
        cost.resize(2*s);
        for (int i=0i;<2*s;i++)cost[i].a01=cost[i].a10=1;
    }
    void update(int i, int& ch0, int& ch1){
        i+=s;
        cost[i].a00+=ch0;
        cost[i].a01+=ch0;
        cost[i].a10+=ch1;
        cost[i].a11+=ch1;
        i/=2;
        while(i!=0){
            cost[i]=cost[i*2]+cost[i*2+1];
            i/=2;
        }
    }
    void calc(int& x, int& y){
        x=min(cost[1].a00, cost[1].a01);
        y=min(cost[1].a10, cost[1].a11);
    }
}seg[MX];
void initialize(int N, vector<int> A, vector<int> B){
    n=N;
    for (int i=0;i<n;i++){
        adj[A[i]].pb(B[i]);
        adj[B[i]].pb(A[i]);
    }
    dfs(1, 0);
    hld(1, 1);
    for (int i=1;i<=n;i++){
        if (i==hldpar[i])seg[i]=segtree(num[i]);
    }
}
void update(int u, int x, int y){
    while(u!=0){
        int hd=hldpar[u];
        int bef0, bef1, aft0, aft1;
        seg[hd].calc(bef0, bef1);
        seg[hd].update(pos[u], x, y);
        seg[hd].calc(aft0, aft1);
        x=min(bef0, bef1+1)-min(aft0, aft1+1);
        y=min(bef0+1, bef1)-min(aft0+1, aft1);
        u=par[hd];
    }
}
int query(){
    int x, y;
    seg[1].calc(x, y);
    return min(x, y);
}
int cat(int v){
    st[v]=1;
    update(v, 0, n);
    return query();
}
int dog(int v){
    st[v]=2;
    update(v, n, 0);
    return query();
}
int neighbor(int v){
    if (st[v]==1)update(v, 0, -n);
    else update(v, -n, 0);
    st[v]=0;
    return query();
}

Compilation message

catdog.cpp:8:1: error: 'vetcor' does not name a type
    8 | vetcor<int>adj[MX];
      | ^~~~~~
catdog.cpp: In function 'void dfs(int, int)':
catdog.cpp:12:20: error: 'adj' was not declared in this scope
   12 |     for (int i=0;i<adj[u].size();i++){
      |                    ^~~
catdog.cpp:15:14: error: too few arguments to function 'void dfs(int, int)'
   15 |         dfs(v);
      |              ^
catdog.cpp:9:6: note: declared here
    9 | void dfs(int u, int pre){
      |      ^~~
catdog.cpp: In function 'void hld(int, int)':
catdog.cpp:23:20: error: 'adj' was not declared in this scope
   23 |     for (int i=0;i<adj[u].size();i++){
      |                    ^~~
catdog.cpp: At global scope:
catdog.cpp:32:44: error: 'cons' has not been declared
   32 |     friend node operator + (const node& a, cons node& b){
      |                                            ^~~~
catdog.cpp:32:53: error: expected ',' or '...' before '&' token
   32 |     friend node operator + (const node& a, cons node& b){
      |                                                     ^
catdog.cpp: In function 'node operator+(const node&, int)':
catdog.cpp:33:13: error: expected ';' before 'c'
   33 |         node c;
      |             ^~
      |             ;
catdog.cpp:33:9: warning: statement has no effect [-Wunused-value]
   33 |         node c;
      |         ^~~~
catdog.cpp:34:9: error: 'c' was not declared in this scope
   34 |         c.a00=min(a.a00+b.a00, a.a01+b.a10);
      |         ^
catdog.cpp:34:25: error: 'b' was not declared in this scope
   34 |         c.a00=min(a.a00+b.a00, a.a01+b.a10);
      |                         ^
catdog.cpp: In constructor 'segtree::segtree(int)':
catdog.cpp:47:20: error: cannot convert 'std::complex<double>' to 'int' in initialization
   47 |         for (int i=0i;<2*s;i++)cost[i].a01=cost[i].a10=1;
      |                    ^~
      |                    |
      |                    std::complex<double>
catdog.cpp:47:23: error: expected primary-expression before '<' token
   47 |         for (int i=0i;<2*s;i++)cost[i].a01=cost[i].a10=1;
      |                       ^
catdog.cpp: In member function 'void segtree::update(int, int&, int&)':
catdog.cpp:57:30: error: no match for 'operator+' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} and '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'})
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from catdog.h:3,
                 from catdog.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:508:5: note: candidate: 'template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)'
  508 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:508:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::reverse_iterator<_Iterator>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from catdog.h:3,
                 from catdog.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1540:5: note: candidate: 'template<class _Iterator> std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)'
 1540 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1540:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::move_iterator<_IteratorL>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6022:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6022 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6022:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:56,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.tcc:1160:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 1160 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.tcc:1160:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   mismatched types 'const _CharT*' and 'node'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:56,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.tcc:1180:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 1180 |     operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.tcc:1180:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6059:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)'
 6059 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6059:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6075:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)'
 6075 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6075:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6087:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6087 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6087:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6093:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)'
 6093 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6093:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6099:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)'
 6099 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6099:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6121:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)'
 6121 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6121:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   mismatched types 'const _CharT*' and 'node'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6127:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)'
 6127 |     operator+(_CharT __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6127:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from catdog.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6133:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*)'
 6133 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6133:5: note:   template argument deduction/substitution failed:
catdog.cpp:57:41: note:   '__gnu_cxx::__alloc_traits<std::allocator<node>, node>::value_type' {aka 'node'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   57 |             cost[i]=cost[i*2]+cost[i*2+1];
      |                                         ^
In file included from /usr/include/c++/10/string:55,