Submission #200665

#TimeUsernameProblemLanguageResultExecution timeMemory
200665FerThugGato12500Arranging Shoes (IOI19_shoes)C++14
0 / 100
116 ms135048 KiB
#include "shoes.h"
#include<iostream>
#include<queue>
using namespace std;
queue<int> closer[2][100001];
int comp[100001];
bool vis[100001];
typedef struct 
{
    int st[400001];
    int N, x, y;
    void build()
    {
        for(int i = 0; i < N*4; i++)
            st[i]=0;
        return;
    }
    int query(int stf, int stf2)
    {
        x=stf; y=stf2;
        return query(0, N-1, 0);
    }
    int query(int ini, int fin, int ind)
    {
        if(ini>y || x>fin)
            return 0;
        if(ini>=x &&  y>=fin)
            return st[ind];
        int mit = (ini+fin)/2, ls=(ind*2)+1, rs=(ind*2)+2;
        return query(ini, mit, ls)+query(mit+1, fin, rs);
    }
    void insert(int stf)
    {
        x=stf;
        insert(0, N-1, 0);
        return;
    }
    void insert(int ini, int fin, int ind)
    {
        if(ini==fin)
        {
            st[ind]++;
            return;
        }
        int mit = (ini+fin)/2, ls=(2*ind)+1, rs=(2*ind)+2;
        insert(ini, mit, ls);
        insert(mit+1, fin, rs);
        st[ind] = st[ls]+st[rs];
        return;
    }
}Wasd;
Wasd mqun;

long long count_swaps(std::vector<int> s) {
	
	int n = s.size();
	for(int i = 0; i < n; i++)
		comp[i]=s[i];
	for(int i = 0; i < n; i++)
        if(comp[i]<0)
            closer[1][comp[i]*-1].push(i);
        else closer[0][comp[i]].push(i);
    mqun.N=n;
    mqun.build();
    long long d=0;
    for(int i = 0; i < n; i++)
        if(!vis[i])
        {
            bool z = false;
            if(comp[i]>0)
                z=true;
            else comp[i]*=-1;
            int j = closer[z][comp[i]].front();
            closer[z][comp[i]].pop();
            closer[!z][comp[i]].pop();
            d+=(j-i+z)-mqun.query(i, j);
            vis[i]=true;
            vis[j]=true;
            mqun.insert(j);
        }
	return d;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:66:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i = 0; i < n; i++)
     ^~~
shoes.cpp:81:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return d;
  ^~~~~~
#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...