Submission #984523

#TimeUsernameProblemLanguageResultExecution timeMemory
984523SzymonKrzywdaArranging Shoes (IOI19_shoes)C++17
10 / 100
1086 ms2028 KiB
//#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

const int base = 2<<18;
int tree[base*2+7];

void edit(int n){
    n+=base;
    while (n>0){
        tree[n] += 1;
        n/=2;
    }
}

int query(int a,int b){
    a+=base-1;
    b+=base+1;
    int wynik=0;
    while (a/2 != b/2){
        if (a%2==0) wynik += tree[a+1];
        if (b%2==1) wynik += tree[b-1];
        a/=2;
        b/=2;
    }
    return wynik;
}


long unsigned int count_swaps(vector<int>S){
    long unsigned int wynik = 0,len=S.size(),idx_1,akt_liczba;
    for (long unsigned int i=0; i<len; i+=2){
        for (long unsigned int j=i; j<len; j++){
            if (S[j]<0){
                idx_1 = j;
                akt_liczba = -S[j];
                break;
            }
            
        }
        for (int j=idx_1; j>i; j--){
            swap(S[j],S[j-1]);
            wynik+=1;
        }
        
        for (long unsigned int j=i; j<len; j++){
            if (S[j]==akt_liczba){
                idx_1 = j;
                break;
            }
        }
        for (int j=idx_1; j>i+1; j--){
            swap(S[j],S[j-1]);
            wynik +=1;
        }
    }
    //cout << S[0] << " " << S[1] << " " << S[2] << " " << endl;
    return wynik;
}

Compilation message (stderr)

shoes.cpp: In function 'long unsigned int count_swaps(std::vector<int>)':
shoes.cpp:41:28: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   41 |         for (int j=idx_1; j>i; j--){
      |                           ~^~
shoes.cpp:47:21: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
   47 |             if (S[j]==akt_liczba){
shoes.cpp:52:28: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   52 |         for (int j=idx_1; j>i+1; j--){
      |                           ~^~~~
shoes.cpp:47:13: warning: 'akt_liczba' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |             if (S[j]==akt_liczba){
      |             ^~
shoes.cpp:41:18: warning: 'idx_1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         for (int j=idx_1; j>i; 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...