Submission #207690

#TimeUsernameProblemLanguageResultExecution timeMemory
207690DodgeBallManArranging Shoes (IOI19_shoes)C++14
50 / 100
1092 ms13944 KiB
#include <bits/stdc++.h> #include "shoes.h" #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 1e5 + 10; vector<int> vec[2*N]; int n, arr[N]; long long ans, fen[N]; long long query( int x ) { long long ret = 0; for( int i = x ; i > 0 ; i -= i & -i ) ret += fen[i]; return ret; } void up( int x ) { for( int i = x ; i < N ; i += i & -i ) fen[i] += 1; } long long count_swaps( vector<int> s ) { n = s.size() / 2; for( int i = 0 ; i < s.size() ; i++ ) vec[s[i]+N].emplace_back( i ); memset( arr, -1, sizeof arr ); for( int i = ( int )s.size() - 1 ; i >= 0 ; i-- ) { if( arr[i] != -1 ) continue ; vec[s[i]+N].pop_back(); int pos = vec[-1*s[i]+N].back(); vec[-1*s[i]+N].pop_back(); if( s[i] < 0 ) arr[i] = n*2-1, arr[pos] = n*2; else arr[i] = n*2, arr[pos] = n*2-1; n--; //printf("%d %d %d %d\n",i,s[i],pos,s[pos]); } //for( int i = 0 ; i < s.size() ; i++ ) printf("%d ",arr[i]); //printf("\n"); for( int i = s.size()-1 ; i >= 0 ; i-- ) { //printf("%d ",arr[i]); ans += query( arr[i] ), up( arr[i] ); } return ans; } /*int main() { int ne; vector<int> vec; scanf("%d",&ne); for( int i = 0, a ; i < ne ; i++ ) { scanf("%d",&a); vec.emplace_back( a ); } printf("%lld",count_swaps( vec ) ); }*/

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < s.size() ; i++ ) vec[s[i]+N].emplace_back( i );
                      ~~^~~~~~~~~~
#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...