제출 #159193

#제출 시각아이디문제언어결과실행 시간메모리
159193BilyanaArranging Shoes (IOI19_shoes)C++17
0 / 100
33 ms28024 KiB
#include<iostream>
#include<queue>
#include<cmath>

using namespace std;

const int MAXN = 20000;
int n, to[MAXN+10], from[MAXN+10];
queue<int> bs[MAXN+10];
int fw[MAXN+10];
long long counter=0;

/*void input()
{
    int temp;
    cin>>n;
    for (int i=0; i<2*n; i++)
    {
        cin>>temp;
        s.push_back(temp);
    }
}*/

void output()
{
    cout<<counter<<endl;
}

void find_place(vector<int> S)
{
    int curr = 0;
    int temp;
    for (int i=0; i<n; i++)
    {
        temp = abs(S[i]);
        if (S[i]>0)
        {
            if (!bs[temp].empty() && bs[temp].front()%2==0)
            {
                //cout<<i<<' '<<bs[temp].front()<<endl;
                to[i] = bs[temp].front()+1;
                bs[temp].pop();
            }
            else
            {
                to[i] = curr+1;
                bs[temp].push(curr+1);
                curr += 2;
            }
        }
        else
        {
            if (!bs[temp].empty() && bs[temp].front()%2==1)
            {
                to[i] = bs[temp].front()-1;
                bs[temp].pop();
            }
            else
            {
                to[i] = curr;
                bs[temp].push(curr);
                curr += 2;
            }
        }
    }
}

void calc_from()
{
    for (int i=0; i<n; i++)
    {
        from[to[i]] = i;
    }
}

void update(int curr, int dif)
{
    while(curr<n)
    {
        fw[curr] += dif;
        curr += curr&(-curr);
    }
}

long long sum(int curr)
{
    int sm = 0;
    while (curr>0)
    {
        sm += fw[curr];
        curr -= curr&(-curr);
    }
}

void sorting()
{
    for (int i=0; i<n; i++)
    {
        int nd=from[i];
        while (nd!=i)
        {
            swap(to[nd], to[nd-1]);
            counter++;
            nd--;
        }
    }
}

void solve(vector<int> S)
{
    n = S.size();
    find_place(S);
    calc_from();
    sorting();
}

long long count_swaps(vector<int> S)
{
    solve(S);
    return counter;
}

/*int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    input();
    solve();
    output();
    return 0;
}*/

/*
3
-2 2 2 -2 -2 2
*/

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

shoes.cpp: In function 'long long int sum(int)':
shoes.cpp:93:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#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...