제출 #1141347

#제출 시각아이디문제언어결과실행 시간메모리
1141347tfgsSnake Escaping (JOI18_snake_escaping)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("avx2") #ifdef LOCAL #include "algo/debug.h" #else template <typename... Args> void dummy(Args&&... args){} #define ps dummy #endif #define f first #define s second template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vs = V<string>; #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define len(x) (int)((x).size()) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define lb lower_bound #define ub upper_bound #define ai2 array<int,2> #define ai3 array<int,3> #define ai4 array<int,4> #define ai5 array<int,5> template<class T> int lwb(const V<T>& a, const T& b) { return lb(all(a),b)-begin(a); } template<class T> int upb(const V<T>& a, const T& b) { return ub(all(a),b)-begin(a); } template<class T> bool ckmin(T& a, const T& b) { return a > b ? a=b, true : false; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a=b, true : false; } #define pct __builtin_popcountll #define ctz __builtin_ctzll #define clz __builtin_clzll constexpr int p2(int x) { return (int)1 << x; } constexpr int bits(int x) { return x == 0 ? 0 : 63-clz(x); } // floor(log2(x)) template<class T>void UNIQUE(V<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } template<class T,class U>void erase(T& t, const U& u) { auto it = t.find(u); assert(it != end(t)); t.erase(it); } template<class F> struct y_combinator_result { F f; template<class T> explicit y_combinator_result(T &&f): f(std::forward<T>(f)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return f(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) yy(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } void dfs(int u) { } void solve() { int L, q; cin >> L >> q; vi arr(p2(L)); for (int i = 0; i < p2(L); i++) { char c; cin >> c; arr[i] = c - '0'; } vi ans(q); V<pair<vi, int>> qs; for (int i = 0; i < q; i++) { vi pat; for (int j = 0; j < L; j++) { char c; cin >> c; pat.pb(c == '?' ? 2 : c - '0'); } qs.pb({ pat, i }); } sort(all(qs), [&](const pair<vi, int>& _a, const pair<vi, int>& _b) { auto a = _a.f, b = _b.f; for (int i = 0; i < L; i++) { bool ba = a[i] == 1; bool bb = b[i] == 1; if (ba != bb) return ba < bb; } return false; }); int l = 0, r = p2(L); vi cur_pre; V<ai2> lrs; auto descend = [&](const vi& pat) { while (len(cur_pre) < len(pat)) { lrs.pb({ l, r }); int m = (l + r) / 2; if (pat[len(cur_pre)] == 2) { for (int i = l; i < m; i++) { arr[i] += arr[i + (r - l) / 2]; } } (pat[len(cur_pre)] == 1 ? l : r) = m; cur_pre.pb(pat[len(cur_pre)]); } }; auto ascend = [&](int new_dep) { while (len(cur_pre) > new_dep) { tie(l, r) = lrs.bk; lrs.pop_back(); int m = (l + r) / 2; if (cur_pre.bk == 2) { for (int i = l; i < m; i++) { arr[i] -= arr[i + (r - l) / 2]; } } cur_pre.pop_back(); } }; for (int i = 0; i < q; i++) { descend(qs[i].f); assert(l == r - 1); ans[qs[i].s] = arr[l]; if (i < q - 1) { int lcp = 0; while (lcp < L && qs[i].f[lcp] == qs[i + 1].f[lcp]) lcp++; ascend(lcp); } } for (int i = 0; i < q; i++) cout << ans[i] << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

snake_escaping.cpp: In lambda function:
snake_escaping.cpp:27:17: error: no match for 'operator=' (operand types are 'std::tuple<int&, int&>' and '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'})
   27 | #define bk back()
      |                 ^
snake_escaping.cpp:104:29: note: in expansion of macro 'bk'
  104 |             tie(l, r) = lrs.bk;
      |                             ^~
In file included from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from snake_escaping.cpp:1:
/usr/include/c++/11/tuple:1290:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1290 |         operator=(const tuple<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/11/tuple:1290:9: note:   template argument deduction/substitution failed:
snake_escaping.cpp:27:17: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} is not derived from 'const std::tuple<_T1, _T2>'
   27 | #define bk back()
      |                 ^
snake_escaping.cpp:104:29: note: in expansion of macro 'bk'
  104 |             tie(l, r) = lrs.bk;
      |                             ^~
In file included from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from snake_escaping.cpp:1:
/usr/include/c++/11/tuple:1300:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1300 |         operator=(tuple<_U1, _U2>&& __in)
      |         ^~~~~~~~
/usr/include/c++/11/tuple:1300:9: note:   template argument deduction/substitution failed:
snake_escaping.cpp:27:17: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} is not derived from 'std::tuple<_T1, _T2>'
   27 | #define bk back()
      |                 ^
snake_escaping.cpp:104:29: note: in expansion of macro 'bk'
  104 |             tie(l, r) = lrs.bk;
      |                             ^~
In file included from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from snake_escaping.cpp:1:
/usr/include/c++/11/tuple:1310:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1310 |         operator=(const pair<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/11/tuple:1310:9: note:   template argument deduction/substitution failed:
snake_escaping.cpp:27:17: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} is not derived from 'const std::pair<_T1, _T2>'
   27 | #define bk back()
      |                 ^
snake_escaping.cpp:104:29: note: in expansion of macro 'bk'
  104 |             tie(l, r) = lrs.bk;
      |                             ^~
In file included from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from snake_escaping.cpp:1:
/usr/include/c++/11/tuple:1321:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1321 |         operator=(pair<_U1, _U2>&& __in)
      |         ^~~~~~~~
/usr/include/c++/11/tuple:1321:9: note:   template argument deduction/substitution failed:
snake_escaping.cpp:27:17: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} is not derived from 'std::pair<_T1, _T2>'
   27 | #define bk back()
      |                 ^
snake_escaping.cpp:104:29: note: in expansion of macro 'bk'
  104 |             tie(l, r) = lrs.bk;
      |                             ^~
In file included from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from snake_escaping.cpp:1:
/usr/include/c++/11/tuple:1267:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(typename std::conditional<__assignable<const _T1&, const _T2&>(), const std::tuple<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = int&; _T2 = int&; typename std::conditional<__assignable<const _T1&, const _T2&>(), const std::tuple<_T1, _T2>&, const std::__nonesuch&>::type = const std::tuple<int&, int&>&]'
 1267 |       operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
      |       ^~~~~~~~
/usr/include/c++/11/tuple:1269:63: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} to 'std::conditional<true, const std::tuple<int&, int&>&, const std::__nonesuch&>::type' {aka 'const std::tuple<int&, int&>&'}
 1267 |       operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1268 |                                      const tuple&,
      |                                      ~~~~~~~~~~~~~             
 1269 |                                      const __nonesuch&>::type __in)
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/11/tuple:1278:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(typename std::conditional<__assignable<_T1, _T2>(), std::tuple<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = int&; _T2 = int&; typename std::conditional<__assignable<_T1, _T2>(), std::tuple<_T1, _T2>&&, std::__nonesuch&&>::type = std::tuple<int&, int&>&&]'
 1278 |       operator=(typename conditional<__assignable<_T1, _T2>(),
      |       ^~~~~~~~
/usr/include/c++/11/tuple:1280:58: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} to 'std::conditional<true, std::tuple<int&, int&>&&, std::__nonesuch&&>::type' {aka 'std::tuple<int&, int&>&&'}
 1278 |       operator=(typename conditional<__assignable<_T1, _T2>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1279 |                                      tuple&&,
      |                                      ~~~~~~~~             
 1280 |                                      __nonesuch&&>::type __in)
      |                                      ~~~~~~~~~~~~~~~~~~~~^~~~