Submission #642948

# Submission time Handle Problem Language Result Execution time Memory
642948 2022-09-20T23:11:40 Z tigar Arranging Shoes (IOI19_shoes) C++14
0 / 100
0 ms 212 KB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll fenvick[200020];

void fenvick_add(int x, int n)
{
    int x1=x;
    while(x1<=n)
    {
        fenvick[x1]++;
        x1+=((-x1)&x1);
    }
}

ll fenvick_sum(int x)
{
    int x1=x, rz=0;
    while(x1>0)
    {
        rz+=fenvick[x1];
        x1-=((-x1)&x1);
    }
    return rz;
}

ll count_swaps(vector<int>S)
{
    int n=S.size()/2;
    stack<pair<int, int> >patike[n+1];
    ll reez=0;
    int poooz[n*2+1]={0};
    for(int i=0; i<2*n; i++)
    {
        if(patike[abs(S[i])].empty())
        {
            if(S[i]<0)patike[abs(S[i])].push({i+1, -1});
            else patike[abs(S[i])].push({i+1, 1});
        }
        else
        {
            if(patike[abs(S[i])].top().second>0 and S[i]>0)
                patike[abs(S[i])].push({i+1, 1});
            else if(patike[abs(S[i])].top().second<0 and S[i]<0)
                patike[abs(S[i])].push({i+1, -1});
            else if(patike[abs(S[i])].top().second<0 and S[i]>0)
            {
                poooz[i+1]=patike[abs(S[i])].top().first;
                poooz[patike[abs(S[i])].top().first]=i+1;
                patike[abs(S[i])].pop();
            }
            else if(patike[abs(S[i])].top().second>0 and S[i]<0)
            {
                poooz[i+1]=patike[abs(S[i])].top().first;
                poooz[patike[abs(S[i])].top().first]=i+1;
                patike[abs(S[i])].pop();
                reez++;
            }
        }
    }
    for(int i=1; i<=2*n; i++)
    {
        if(fenvick[i]==0)
        {
            fenvick_add(i, 2*n);
            fenvick_add(poooz[i], 2*n);
        }
        if(fenvick[i]==1)
        {
            reez+=fenvick_sum(i)-fenvick_sum(poooz[i]);
        }
    }
    return reez;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -