제출 #583509

#제출 시각아이디문제언어결과실행 시간메모리
583509lcjArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms212 KiB
#include <bits/stdc++.h>
#include "shoes.h"

#define LSOne(s) ((s) & -(s))
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

struct FenwickTree {
    vector<ll> ft;
    FenwickTree(int n) : ft(n+1) {}
    ll rsq(int i) {
        ll su = 0;
        for (; i > 0; i -= LSOne(i)) {
            su += ft[i];
        }
        return su;
    }
    void update(int i, int dv) {
        for (; i < (int)ft.size(); i += LSOne(i)) {
            ft[i] += dv;
        }
    }
};

ll count_swaps(std::vector<int> s) {
    FenwickTree ft(s.size());
    map<int, int> open;
    int csum = 0;
    vector<int> mypartner(s.size());
    for (int i = 0; i < s.size(); i++)
    {
        if (open.find(-s[i]) != open.end()) {
            mypartner[open[-s[i]]] = i;
            mypartner[i] = open[-s[i]];
            open.erase(-s[i]);
            csum += (s[i] < 0);
        }
        else {
            open[s[i]] = i;
        }
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (mypartner[i] < i) continue;
        csum += (mypartner[i]+ft.rsq(mypartner[i]+1))-(i+ft.rsq(i+1))-1;
        ft.update(1, 1);
        ft.update(mypartner[i]+1, -1);
    }
    return csum;
}

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

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
shoes.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...