Submission #1286395

#TimeUsernameProblemLanguageResultExecution timeMemory
1286395harryleeeArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int> a){
    int n = (int)a.size() / 2;

    vector<queue<int>> q(2 * n + 1);
    vector<int> last_ind(a.size());

    for (int i = 0; i < (int)a.size(); ++i){
        if (q[-a[i] + n].empty()){
            q[a[i] + n].push(i);
            last_ind[i] = i;
        }
        else{
            int pre = q[-a[i] + n].front();
            q[-a[i] + n].pop();
            last_ind[i] = pre;
        }
    }

    struct SEGMENT_TREE{
        vector<vector<int>> st;
        SEGMENT_TREE(int m, const vector<int>& vec){
            st.resize(4 * m);
            build(1, 0, m - 1, vec);
        }
        void build(int ind, int l, int r, const vector<int>& vec){
            if (l == r){
                st[ind].push_back(vec[l]);
                return;
            }
            int mid = (l + r) >> 1;
            build(ind << 1, l, mid, vec);
            build(ind << 1 | 1, mid + 1, r, vec);

            const vector<int>& L = st[ind << 1];
            const vector<int>& R = st[ind << 1 | 1];
            vector<int> tmp;
            tmp.reserve(L.size() + R.size());
            size_t i = 0, j = 0;
            while (i < L.size() && j < R.size()){
                if (L[i] <= R[j]) tmp.push_back(L[i++]);
                else tmp.push_back(R[j++]);
            }
            while (i < L.size()) tmp.push_back(L[i++]);
            while (j < R.size()) tmp.push_back(R[j++]);
            st[ind].swap(tmp);
        }
        long long get(int ind, int l, int r, int lb, int rb, int val){
            if (lb > rb) return 0;
            if (lb <= l && r <= rb){
                int it = upper_bound(st[ind].begin(), st[ind].end(), val) - st[ind].begin();
                return (long long)st[ind].size() - it;
            }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:55:14: error: expected '}' at end of input
   55 |             }
      |              ^
shoes.cpp:22:24: note: to match this '{'
   22 |     struct SEGMENT_TREE{
      |                        ^
shoes.cpp: In member function 'long long int count_swaps(std::vector<int>)::SEGMENT_TREE::get(int, int, int, int, int, int)':
shoes.cpp:55:14: error: expected '}' at end of input
   55 |             }
      |              ^
shoes.cpp:50:70: note: to match this '{'
   50 |         long long get(int ind, int l, int r, int lb, int rb, int val){
      |                                                                      ^
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:55:14: error: expected unqualified-id at end of input
   55 |             }
      |              ^
shoes.cpp:55:14: error: expected '}' at end of input
shoes.cpp:4:37: note: to match this '{'
    4 | long long count_swaps(vector<int> a){
      |                                     ^
shoes.cpp:55:14: warning: no return statement in function returning non-void [-Wreturn-type]
   55 |             }
      |              ^