QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620676#9419. Normal Friendsucup-team004Compile Error//C++237.9kb2024-10-07 20:19:162024-10-07 20:19:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 20:19:16]
  • 评测
  • [2024-10-07 20:19:16]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

constexpr int N = 7E5;

struct Node {
    int p;
    int ch[2];
    int rev;
    int flip;
    int val1;
    int sum1;
    int val2;
    int sum2;
    Node() : p(0), ch {0, 0}, rev(0), flip(0), val1(0), sum1(0), val2(0), sum2(0) {}
} t[2 * N];

int tlc[N], trc[N];
int fl[N];

int tot = 0;

void reverse(int o) {
    if (o) {
        std::swap(t[o].ch[0], t[o].ch[1]);
        t[o].rev ^= 1;
    }
}
void flip(int o) {
    if (o) {
        t[o].flip ^= 1;
        if (o < N) {
            std::swap(t[o].val1, t[o].val2);
            std::swap(t[o].sum1, t[o].sum2);
        }
    }
}
void push(int o) {
    if (t[o].rev) {
        reverse(t[o].ch[0]);
        reverse(t[o].ch[1]);
        t[o].rev = 0;
    }
    if (t[o].flip) {
        if (o > N) {
            fl[o - N] ^= 1;
            flip(t[o].ch[0]);
            flip(t[o].ch[1]);
        } else {
            flip(t[o].ch[0]);
            flip(t[o].ch[1]);
        }
        t[o].flip = 0;
    }
}
void pull(int o) {
    t[o].sum1 = t[t[o].ch[0]].sum1 + t[o].val1 + t[t[o].ch[1]].sum1;
    t[o].sum2 = t[t[o].ch[0]].sum2 + t[o].val2 + t[t[o].ch[1]].sum2;
}
bool isroot(int o) {
    return t[o].p == 0 || (t[t[o].p].ch[0] != o && t[t[o].p].ch[1] != o);
}
int pos(int o) {
    return t[t[o].p].ch[1] == o;
}
void pushAll(int o) {
    if (!isroot(o)) {
        pushAll(t[o].p);
    }
    push(o);
}
void rotate(int o) {
    int q = t[o].p;
    int x = !pos(o);
    t[q].ch[!x] = t[o].ch[x];
    if (t[o].ch[x]) {
        t[t[o].ch[x]].p = q;
    }
    t[o].p = t[q].p;
    if (!isroot(q)) {
        t[t[q].p].ch[pos(q)] = o;
    }
    t[o].ch[x] = q;
    t[q].p = o;
    pull(q);
}
void splay(int o) {
    pushAll(o);
    while (!isroot(o)) {
        if (!isroot(t[o].p)) {
            if (pos(o) == pos(t[o].p)) {
                rotate(t[o].p);
            } else {
                rotate(o);
            }
        }
        rotate(o);
    }
    pull(o);
}

int select1(int o, int x) {
    push(o);
    if (x <= t[t[o].ch[0]].sum1) {
        return select1(t[o].ch[0], x);
    }
    x -= t[t[o].ch[0]].sum1;
    if (x <= t[o].val1) {
        return o;
    }
    x -= t[o].val1;
    return select1(t[o].ch[1], x);
}

int select2(int o, int x) {
    push(o);
    if (x <= t[t[o].ch[0]].sum2) {
        return select2(t[o].ch[0], x);
    }
    x -= t[t[o].ch[0]].sum2;
    if (x <= t[o].val2) {
        return o;
    }
    x -= t[o].val2;
    return select2(t[o].ch[1], x);
}

std::array<int, 2> split2(int o, int x) {
    if (x == 0) {
        return {0, o};
    }
    o = select2(o, x);
    splay(o);
    int p = t[o].ch[1];
    t[o].ch[1] = 0;
    t[p].p = 0;
    pull(o);
    return {o, p};
}

int findFirst(int o) {
    while (t[o].ch[0]) {
        push(o);
        o = t[o].ch[0];
    }
    return o;
}

int findLast(int o) {
    while (t[o].ch[1]) {
        push(o);
        o = t[o].ch[1];
    }
    return o;
}

int merge(int a, int b) {
    if (!a) {
        return b;
    }
    if (!b) {
        return a;
    }
    a = findLast(a);
    splay(a);
    t[a].ch[1] = b;
    t[b].p = a;
    pull(a);
    return a;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> mid(n);
    mid[0] = n;
    for (int i = 1; i < n; i++) {
        std::cin >> mid[i];
    }
    
    int cur = n + 1;
    int i = 0;
    
    auto dfs = [&](auto &&dfs, int l, int r) -> int {
        if (r - l == 1) {
            t[r + N].val1 = 1;
            t[r + N].val2 = 1;
            pull(r + N);
            return r;
        }
        int m = mid[i++];
        assert(l < m && m < r);
        int o = ++cur;
        
        int lc = dfs(dfs, l, m);
        int rc = dfs(dfs, m, r);
        
        t[o].val1 = 1;
        t[o].ch[1] = rc;
        t[rc].p = o;
        pull(o);
        
        tlc[o] = lc + N;
        t[tlc[o]].ch[1] = tlc[rc];
        if (tlc[rc]) {
            t[tlc[rc]].p = tlc[o];
        }
        pull(tlc[o]);
        
        t[o + N].val1 = t[tlc[o]].sum1 + 1;
        t[o + N].val2 = 1;
        pull(o + N);
        
        return o;
    };
    int rt = dfs(dfs, 0, n + 1);
    
    for (int i = 0; i < m; i++) {
        int x;
        std::cin >> x;
        x++;
        
        int o = rt;
        std::vector<int> stk;
        while (true) {
            int p = findFirst(o);
            splay(p);
            if (fl[p]) {
                std::swap(tlc[p], trc[p]);
                flip(tlc[p]);
                flip(trc[p]);
                flip(p);
                fl[p] = 0;
            }
            if (x <= t[tlc[p]].sum1) {
                int q = select1(tlc[p], x);
                splay(q);
                tlc[p] = q;
                x -= t[t[q].ch[0]].sum1;
                int r = select1(o, t[t[q].ch[0]].sum2 + 1);
                splay(r);
                stk.push_back(r);
                o = q - N;
            } else {
                x -= t[tlc[p]].sum1;
                if (x == 1) {
                    break;
                } else {
                    x--;
                    int q = select1(trc[p], t[trc[p]].sum1 - x + 1);
                    splay(q);
                    trc[p] = q;
                    x -= t[t[q].ch[1]].sum1;
                    int r = select2(o, t[t[q].ch[0]].sum2 + 1);
                    splay(r);
                    stk.push_back(r);
                    o = q - N;
                }
            }
        }
        
        while (!stk.empty()) {
            splay(o);
            o = findFirst(o);
            splay(o);
            
            int q = stk.back();
            stk.pop_back();
            splay(q);
            int p = findFirst(q);
            splay(p);
            splay(q);
            
            int r = t[q].ch[1];
            t[q].ch[1] = 0;
            t[r].p = 0;
            pull(q);
            r = findFirst(r);
            splay(r);
            
            std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
            std::tie(trc[p], trc[r]) = split2(trc[p], t[q].sum2);
            
            if (t[q].val1) {
                t[q].val1 = 0;
                t[q].val2 = 1;
                t[q].ch[1] = o;
                t[o].p = q;
                pull(q);
                
                int s = findLast(tlc[p]);
                splay(s);
                tlc[p] = t[s].ch[0];
                t[tlc[p]].p = 0;
                t[s].ch[0] = 0;
                
                int u = r + N;
                push(u);
                t[u].val1 = t[tlc[r]].sum1 + 1 + t[trc[r]].sum1;
                t[u].ch[0] = trc[p];
                if (trc[p]) {
                    t[trc[p]].p = u;
                }
                pull(u);
                trc[p] = u;
            } else {
                t[q].val2 = 0;
                t[q].val1 = 1;
                t[q].ch[1] = o;
                t[o].p = q;
                pull(q);
                
                int s = findLast(trc[p]);
                splay(s);
                trc[p] = t[s].ch[0];
                t[trc[p]].p = 0;
                t[s].ch[0] = 0;
                
                int u = r + N;
                push(u);
                t[u].val1 = t[tlc[r]].sum1 + 1 + t[trc[r]].sum1;
                t[u].ch[0] = tlc[p];
                if (tlc[p]) {
                    t[tlc[p]].p = u;
                }
                pull(u);
                tlc[p] = u;
            }
            
            tlc[p] = merge(tlc[p], tlc[o]);
            trc[p] = merge(trc[p], trc[o]);
        }
        
        std::cout << t[tlc[rt]].sum2 << "\n";
        reverse(tlc[rt]);
        flip(tlc[rt]);
    }
    
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:288:64: error: no match for ‘operator=’ (operand types are ‘std::tuple<int&, int&>’ and ‘std::array<int, 2>’)
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
In file included from /usr/include/c++/13/bits/uses_allocator_args.h:38,
                 from /usr/include/c++/13/bits/memory_resource.h:41,
                 from /usr/include/c++/13/string:58,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:1:
/usr/include/c++/13/tuple:1628:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1628 |         operator=(const tuple<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1628:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘const std::tuple<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1638:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1638 |         operator=(tuple<_U1, _U2>&& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1638:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘std::tuple<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1664:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) const requires (is_assignable_v<const _T1&, const _U1&>) && (is_assignable_v<const _T2&, const _U2&>) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1664 |         operator=(const tuple<_U1, _U2>& __in) const
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1664:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘const std::tuple<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1674:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) const requires (is_assignable_v<const _T1&, _U1>) && (is_assignable_v<const _T2&, _U2>) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1674 |         operator=(tuple<_U1, _U2>&& __in) const
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1674:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘std::tuple<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1686:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1686 |         operator=(const pair<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1686:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘const std::pair<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1697:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int&; _T2 = int&]’
 1697 |         operator=(pair<_U1, _U2>&& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1697:9: note:   template argument deduction/substitution failed:
answer.code:288:64: note:   ‘std::array<int, 2>’ is not derived from ‘std::pair<_T1, _T2>’
  288 |             std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
      |                                                                ^
/usr/include/c++/13/tuple:1708:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(c...