제출 #1293110

#제출 시각아이디문제언어결과실행 시간메모리
1293110trandaihao5555Arranging Shoes (IOI19_shoes)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include "shoes.h"

#define int long long

#define debug     cout << "ok\n";
#define SQR(x)    (1LL * ((x) * (x)))
#define MASK(i)   (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi        first
#define se        second
#define pb        push_back

#define mp make_pair
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;

//using namespace std;

const int M = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);

const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};

template<class _, class __>
    bool minimize(_ &x, const __ y){
        if(x > y){
            x = y;
            return true;
        } else return false;
    }
template<class _, class __>
    bool maximize(_ &x, const __ y){
        if(x < y){
            x = y;
            return true;
        } else return false;
    }

template<class _,class __>
    void Add(_ &x, const __ y) {
        x += y;
        if (x >= M) {
            x -= M;
        }
        return;
    }

template<class _,class __>
    void Diff(_ &x, const __ y) {
        x -= y;
        if (x < 0) {
            x += M;
        }
        return;
    }

//--------------------------------------------------------------

const int MaxN = 1e6+7;

vi nen;
multiset<int> lis[MaxN][2];
bool ch[MaxN];

struct FenwickTree {
    int Tr[MaxN];

    void Upd(int u,int v) {
        u++;
        for (; u < MaxN; u += u&-u) {
            Tr[u]+=v;
        }
        return;
    }

    int Get(int u) {
        u++;
        if (u < 0) return 0;
        int res = 0;
        for (; u; u -= u&-u) {
            res += Tr[u];
        }
        return res;
    }
} Fw;

int count_swaps(vi S) {
    for (int x : S) nen.pb(abs(x));
    sort(nen.begin(),nen.end());
    nen.erase(unique(nen.begin(),nen.end()),nen.end());
    for (int i=0;i<S.size();i++) {
        int & x = S[i];
        int tmp = x / abs(x);
        if (tmp == -1) tmp = 0;
        x = lower_bound(nen.begin(),nen.end(),abs(x)) - nen.begin() + 1;
        lis[x][tmp].insert(i);
    }
    vi res;
    for (int i=0;i<S.size();i++) {
        if (ch[i]) continue;
        res.pb(*lis[S[i]][0].begin());
        res.pb(*lis[S[i]][1].begin());
        ch[*lis[S[i]][0].begin()] = true;
        ch[*lis[S[i]][1].begin()] = true;
        lis[S[i]][0].erase(lis[S[i]][0].begin());
        lis[S[i]][1].erase(lis[S[i]][1].begin());
    }
    reverse(res.begin(),res.end());
    ll ans = 0;
    for (int x : res) {
        ans += Fw.Get(x);
        Fw.Upd(x,1);
    }
    return ans;
}

//void sol() {
//    cout << count_swaps({2, 1, -1, -2});
//}
//
//signed main() {
////    freopen("test.inp","r",stdin);
////    freopen("test.out","w",stdout);
//    FAST
//    int t=1;
////    cin >> t;
//    while (t--) sol();
//}

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

shoes.cpp:17:12: error: 'vector' does not name a type
   17 | #define vi vector<int>
      |            ^~~~~~
shoes.cpp:73:1: note: in expansion of macro 'vi'
   73 | vi nen;
      | ^~
shoes.cpp:74:1: error: 'multiset' does not name a type
   74 | multiset<int> lis[MaxN][2];
      | ^~~~~~~~
shoes.cpp:17:12: error: 'long long int count_swaps' redeclared as different kind of entity
   17 | #define vi vector<int>
      |            ^~~~~~
shoes.cpp:99:17: note: in expansion of macro 'vi'
   99 | int count_swaps(vi S) {
      |                 ^~
In file included from shoes.cpp:2:
shoes.h:7:11: note: previous declaration 'long long int count_swaps(std::vector<int>)'
    7 | long long count_swaps(std::vector<int> S);
      |           ^~~~~~~~~~~
shoes.cpp:17:12: error: 'vector' was not declared in this scope
   17 | #define vi vector<int>
      |            ^~~~~~
shoes.cpp:99:17: note: in expansion of macro 'vi'
   99 | int count_swaps(vi S) {
      |                 ^~
shoes.cpp:17:12: note: suggested alternatives:
   17 | #define vi vector<int>
      |            ^~~~~~
shoes.cpp:99:17: note: in expansion of macro 'vi'
   99 | int count_swaps(vi S) {
      |                 ^~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from shoes.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
shoes.cpp:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
shoes.cpp:17:19: note: in expansion of macro 'int'
   17 | #define vi vector<int>
      |                   ^~~
shoes.cpp:99:17: note: in expansion of macro 'vi'
   99 | int count_swaps(vi S) {
      |                 ^~