Submission #738688

#TimeUsernameProblemLanguageResultExecution timeMemory
738688aykhnMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "dna.h" // author: aykhn using namespace std; typedef long long ll; const int oo = INT_MAX; const ll ooo = LONG_MAX; const ll mod = 1e9 + 7; #define OPT ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pii pair<int,int> #define pll pair<ll,ll> #define all(v) v.begin(), v.end() #define mpr make_pair #define pb push_back #define ts to_string #define fi first #define se second #define inf 0x3F3F3F3F #define ins insert #define infll 0x3F3F3F3F3F3F3F3FLL #define bpc __builtin_popcount struct data { int AC = 0; int AT = 0; int CA = 0; int CT = 0; int TA = 0; int TC = 0; }; int sz = 1; vector<data> tree; string a, b; data MERGE(data one, data two) { data res; res.AT = one.AT + two.AT; res.AC = one.AC + two.AC; res.CA = one.CA + two.CA; res.CT = one.CT + two.CT; res.TA = one.TA + two.TA; res.TC = one.TC + two.TC; return res; } void build(int l, int r, int x) { if (l + 1 == r) { if (l < a.length() && a[l] != b[l]) { if (a[l] == 'A' && b[l] == 'C') tree[x].AC++; else if (a[l] == 'A' && b[l] == 'T') tree[x].AT++; else if (a[l] == 'C' && b[l] == 'A') tree[x].CA++; else if (a[l] == 'C' && b[l] == 'T') tree[x].CT++; else if (a[l] == 'T' && b[l] == 'A') tree[x].TA++; else if (a[l] == 'T' && b[l] == 'C') tree[x].TC++; } return; } int mid = (l + r) >> 1; build(l, mid, 2*x+1); build(mid, r, 2*x+2); tree[x] = MERGE(tree[2*x+1], tree[2*x+2]); } data get(int lx, int rx, int l, int r, int x) { if (l >= rx || r <= lx) { data temp; return temp; } if (l >= lx && r <= rx) return tree[x]; int mid = (l + r) >> 1; return MERGE(get(lx, rx, l, mid, 2*x+1), get(lx, rx, mid, r, 2*x+2)); } void init(string s1, string s2) { a = s1; b = s2; int n = s1.length(); while (sz < n) sz <<= 1; data temp; temp.AC = temp.AT = temp.CA = temp.CT = temp.TA = temp.TC = 0; tree.assign(sz * 2, temp); build(0, sz, 0); } int get_distance(int l, int r) { data x = get(l, r + 1, 0, sz, 0); if (x.AT + x.AC != x.TA + x.CA || x.CA + x.CT != x.AC + x.TC || x.TA + x.TC != x.AT + x.CT) return -1; //cout << "AC: " << x.AC << endl << "AT: " << x.AT << endl << "CA: " << x.CA << endl << "CT: " << x.CT << endl << "TA: " << x.TA << endl << "TC: " << x.TC << endl << endl; int res = 0; int temp = min(x.AT, x.TA); res += temp; x.AT -= temp; x.TA -= temp; temp = min(x.AC, x.CA); res += temp; x.AC -= temp; x.CA -= temp; temp = min(x.CT, x.TC); res += temp; x.CT -= temp; x.TC -= temp; temp = min({x.AC, x.CT, x.TA}); res += temp*2; x.AC -= temp; x.CT -= temp; x.TA -= temp; temp = min({x.AT, x.TC, x.CA}); res += temp*2; return res; }

Compilation message (stderr)

dna.cpp:41:12: error: template argument 1 is invalid
   41 | vector<data> tree;
      |            ^
dna.cpp:41:12: error: template argument 2 is invalid
dna.cpp:45:1: error: reference to 'data' is ambiguous
   45 | data MERGE(data one, data two)
      | ^~~~
In file included from /usr/include/c++/10/string:54,
                 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 dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
dna.cpp:30:8: note:                 'struct data'
   30 | struct data
      |        ^~~~
dna.cpp: In function 'void build(int, int, int)':
dna.cpp:63:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         if (l < a.length() && a[l] != b[l])
      |             ~~^~~~~~~~~~~~
dna.cpp:65:49: error: invalid types 'int[int]' for array subscript
   65 |             if (a[l] == 'A' && b[l] == 'C') tree[x].AC++;
      |                                                 ^
dna.cpp:66:54: error: invalid types 'int[int]' for array subscript
   66 |             else if (a[l] == 'A' && b[l] == 'T') tree[x].AT++;
      |                                                      ^
dna.cpp:67:54: error: invalid types 'int[int]' for array subscript
   67 |             else if (a[l] == 'C' && b[l] == 'A') tree[x].CA++;
      |                                                      ^
dna.cpp:68:54: error: invalid types 'int[int]' for array subscript
   68 |             else if (a[l] == 'C' && b[l] == 'T') tree[x].CT++;
      |                                                      ^
dna.cpp:69:54: error: invalid types 'int[int]' for array subscript
   69 |             else if (a[l] == 'T' && b[l] == 'A') tree[x].TA++;
      |                                                      ^
dna.cpp:70:54: error: invalid types 'int[int]' for array subscript
   70 |             else if (a[l] == 'T' && b[l] == 'C') tree[x].TC++;
      |                                                      ^
dna.cpp:81:9: error: invalid types 'int[int]' for array subscript
   81 |     tree[x] = MERGE(tree[2*x+1], tree[2*x+2]);
      |         ^
dna.cpp:81:25: error: invalid types 'int[int]' for array subscript
   81 |     tree[x] = MERGE(tree[2*x+1], tree[2*x+2]);
      |                         ^
dna.cpp:81:38: error: invalid types 'int[int]' for array subscript
   81 |     tree[x] = MERGE(tree[2*x+1], tree[2*x+2]);
      |                                      ^
dna.cpp:81:15: error: 'MERGE' was not declared in this scope
   81 |     tree[x] = MERGE(tree[2*x+1], tree[2*x+2]);
      |               ^~~~~
dna.cpp: At global scope:
dna.cpp:84:1: error: reference to 'data' is ambiguous
   84 | data get(int lx, int rx, int l, int r, int x)
      | ^~~~
In file included from /usr/include/c++/10/string:54,
                 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 dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
dna.cpp:30:8: note:                 'struct data'
   30 | struct data
      |        ^~~~
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:109:5: error: reference to 'data' is ambiguous
  109 |     data temp;
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 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 dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
dna.cpp:30:8: note:                 'struct data'
   30 | struct data
      |        ^~~~
dna.cpp:110:5: error: 'temp' was not declared in this scope
  110 |     temp.AC = temp.AT = temp.CA = temp.CT = temp.TA = temp.TC = 0;
      |     ^~~~
dna.cpp:112:10: error: request for member 'assign' in 'tree', which is of non-class type 'int'
  112 |     tree.assign(sz * 2, temp);
      |          ^~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:119:5: error: reference to 'data' is ambiguous
  119 |     data x = get(l, r + 1, 0, sz, 0);
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 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 dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
dna.cpp:30:8: note:                 'struct data'
   30 | struct data
      |        ^~~~
dna.cpp:121:9: error: 'x' was not declared in this scope
  121 |     if (x.AT + x.AC != x.TA + x.CA || x.CA + x.CT != x.AC + x.TC || x.TA + x.TC != x.AT + x.CT) return -1;
      |         ^
dna.cpp:127:20: error: 'x' was not declared in this scope
  127 |     int temp = min(x.AT, x.TA);
      |                    ^
dna.cpp:145:34: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
  145 |     temp = min({x.AC, x.CT, x.TA});
      |                                  ^
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 dna.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
dna.cpp:145:34: note:   candidate expects 2 arguments, 1 provided
  145 |     temp = min({x.AC, x.CT, x.TA});
      |                                  ^
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 dna.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
dna.cpp:145:34: note:   candidate expects 3 arguments, 1 provided
  145 |     temp = min({x.AC, x.CT, x.TA});
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
dna.cpp:153:34: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
  153 |     temp = min({x.AT, x.TC, x.CA});
      |                                  ^
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 dna.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
dna.cpp:153:34: note:   candidate expects 2 arguments, 1 provided
  153 |     temp = min({x.AT, x.TC, x.CA});
      |                                  ^
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 dna.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
dna.cpp:153:34: note:   candidate expects 3 arguments, 1 provided
  153 |     temp = min({x.AT, x.TC, x.CA});
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed: