제출 #645360

#제출 시각아이디문제언어결과실행 시간메모리
645360_petar_bArranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define MAXN 200010
#define DELTA 100001
#define pb push_back
#define ll long long
#define fi first
#define se second
#define mp make_pair

//using namespace std;

int n, t[4*MAXN], par[MAXN], tleaf[MAXN];
queue<int> posOf[MAXN];

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = t[v*2] + t[v*2+1];
    }
}

int sum(int v, int tl, int tr, int l, int r)
{
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm)) + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
}

void update(int v, int tl, int tr, int pos)
{
    if (tl == tr)
        t[v] = 0;
    else
    {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos);
        else
            update(v*2+1, tm+1, tr, pos);
        t[v] = t[v*2] + t[v*2+1];
    }
}

long long count_swaps(std::vector<int> s)
{
    n = s.size();
    for (int i = n-1; i >= 0; i--)
    {
        tleaf[i] = 1;
        int other = DELTA - s[i];
        if (!posOf[other].empty())
        {
            par[i] = posOf[other].front();
            par[par[i]] = i;
            tleaf[par[i]] = 0;
            posOf[other].pop();
        }
        else
        {
            par[i] = -1;
            posOf[s[i]+DELTA].push(i);
        }
    }
    build(1, 0, n-1);
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (tleaf[i] == 1)
        {
            res += sum(1, 0, n-1, i+1, par[i]-1);
            //tleaf[par[i]] = 0;
            update(1, 0, n-1, par[i]);
            if (s[i] > 0) res++;
        }
    }
    return res;
}

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

shoes.cpp:14:1: error: 'queue' does not name a type; did you mean 'sigqueue'?
   14 | queue<int> posOf[MAXN];
      | ^~~~~
      | sigqueue
shoes.cpp: In function 'int sum(int, int, int, int, int)':
shoes.cpp:36:32: error: 'min' was not declared in this scope; did you mean 'std::min'?
   36 |     return sum(v*2, tl, tm, l, min(r, tm)) + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
      |                                ^~~
      |                                std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
shoes.cpp:36:67: error: 'max' was not declared in this scope; did you mean 'std::max'?
   36 |     return sum(v*2, tl, tm, l, min(r, tm)) + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
      |                                                                   ^~~
      |                                                                   std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:61:14: error: 'posOf' was not declared in this scope
   61 |         if (!posOf[other].empty())
      |              ^~~~~