Submission #158575

# Submission time Handle Problem Language Result Execution time Memory
158575 2019-10-17T23:55:25 Z phungha Arranging Shoes (IOI19_shoes) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100001;
int n, BIT[200001];
vector<pair<int, int> > ord[100001], a;
long long ans = 0;

void update(int i, int v) {
    while (i <= 200000) {
        BIT[i] += v;
        i += i & (-i);
    }
}

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += BIT[i];
        i -= i & -i;
    }
    return s;
}

int main() {
    //freopen("test117.in", "r", stdin);
    //freopen("test01.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= 2*n; i++) {
        int s;
        scanf("%d", &s);
        ord[abs(s)].push_back({s, i});
    }

    for (int i = 1; i <= n; i++) {
        sort(ord[i].begin(), ord[i].end());
        for (int j = 0; j < ord[i].size()/2; j++) {
            int l = ord[i][j].second;
            int r = ord[i][j + ord[i].size()/2].second;
            if (l > r) {
                swap(l, r);
                ans++;
            }
            a.push_back({l, r});
        }
    }
    sort(a.begin(), a.end());

    for (int i = 1; i <= 2*n; i++)
        update(i, 1);
    for (int i = 0; i < a.size(); i++) {
        ans += sum(a[i].second-1) - sum(a[i].first);
        update(a[i].first, -1);
        update(a[i].second, -1);
    }
    printf("%lld\n", ans);
}

Compilation message

shoes.cpp: In function 'int main()':
shoes.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < ord[i].size()/2; j++) {
                         ~~^~~~~~~~~~~~~~~~~
shoes.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
shoes.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
shoes.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &s);
         ~~~~~^~~~~~~~~~
/tmp/ccErhJxF.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccBZecmv.o:shoes.cpp:(.text.startup+0x0): first defined here
/tmp/ccErhJxF.o: In function `main':
grader.cpp:(.text.startup+0x282): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status