제출 #379982

#제출 시각아이디문제언어결과실행 시간메모리
379982Dan4LifeArranging Shoes (IOI19_shoes)C++17
100 / 100
221 ms12776 KiB
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;

int Fenwick[200010], n;
void update(int pos, int val) { while(pos<=200000)Fenwick[pos]+=val, pos+=pos&-pos; }
int sum(int x) { int S = 0; while(x)S+=Fenwick[x],x-=x&-x; return S; }
int query(int l, int r) { return sum(r-1)-sum(l); }

long long count_swaps(vector<int> s)
{
    n = (int)s.size()/2;
    vector<pair<int,int> > ord[200010], v;
    for(int i = 0; i < 2*n; i++) ord[abs(s[i])].push_back({s[i],i});
    long long ans = 0;
    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, r = ord[i][j+ord[i].size()/2].second;
            if(l>r) ans++, swap(l,r);
            v.push_back({l+1,r+1});
        }
    }
    sort(v.begin(),v.end());
    for(int i = 1; i <= 2*n; i++) update(i,1);
    for(auto u : v)
    {
        int l = u.first, r = u.second;
        ans+=query(l,r), update(l,-1),update(r,-1);
    }
    return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:19:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for(int j = 0; j < ord[i].size()/2; j++)
      |                        ~~^~~~~~~~~~~~~~~~~
#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...