제출 #985896

#제출 시각아이디문제언어결과실행 시간메모리
985896LucaIlieArranging Shoes (IOI19_shoes)C++17
50 / 100
24 ms15196 KiB
#include "shoes.h" #include <iostream> #include <vector> using namespace std; #define nmax 100001 int v[nmax]; vector <int> fst[nmax], fdr[nmax]; int n; int aint[4 * nmax]; void afiseaza( int node, int l, int r ) { ///cout << node << " " << l << " " << r << " " << aint[node] << "\n"; if( l == r ) return; afiseaza( 2 * node, l, (l + r) / 2 ); afiseaza( 2 * node + 1, (l + r) / 2 + 1, r ); } int query( int node, int l, int r, int ql, int qr ) { if( r < ql || qr < l ) return 0; if( ql <= l && r <= qr ) return aint[node]; return query( 2 * node, l, (l + r) / 2, ql, qr ) + query( 2 * node + 1, (l + r) / 2 + 1, r, ql, qr ); } void update( int node, int l, int r, int qpoz, int val ) { if( r < qpoz || qpoz < l ) return; if( l == r ) aint[node] += val; else { update( 2 * node, l, (l + r) / 2, qpoz, val ); update( 2 * node + 1, (l + r) / 2 + 1, r, qpoz, val ); aint[node] = aint[2 * node] + aint[2 * node + 1]; } } //vreau distanta intre doua pozitii //un interval se muta mai la dreapta /*int find_pair( int l ) { int i, j, rez = 0; if( v[l] < 0 ) { for( i = l + 1; i < n; i++ ) { if( v[i] + v[l] == 0 ) break; } //toate pozitiile de la l la i cresc cu 1 //rez = query( 1, 1, n, 1, n ) - query( 1, 1, n, 1, i ); //update( 1, 1, n, i, 1 ); //pozitia l si pozitia i v[i] = 0; return rez; } else if( v[j] > 0 ){ for( i = l + 1; i < n; i++ ) { if( v[i] + v[l] == 0 ) break; } for( j = i; j > l + 1; j-- ) v[j] = v[j - 1]; v[i] = 0; return i - l; } return 0; } */ long long count_swaps( vector<int> s) { int i, l, rez = 0, j; n = s.size(); for( i = 0; i < n; i++ ) v[i] = s[i]; for( i = n - 1; i >= 0; i-- ) { if( v[i] < 0 ) fst[-v[i]].push_back( i ); else fdr[v[i]].push_back( i ); } for( l = 0; l < n; l ++ ) { if( v[l] == 0 ) continue; if( v[l] < 0 ) { fst[-v[l]].pop_back(); i = fdr[-v[l]].back(); fdr[-v[l]].pop_back(); } else { fdr[v[l]].pop_back(); i = fst[v[l]].back(); fst[v[l]].pop_back(); } // toate poz de la l la i cresc cu 1 ///cout << "i " << i << " l " << l << "\n"; rez += i - l - 1 - ( query( 1, 1, n, 1, i ) - query( 1, 1, n, 1, l ) ); if( v[l] > 0 ) rez++; update( 1, 1, n, i, 1 ); v[i] = 0; /*cout << "rez " << rez << "\n"; cout << "aint\n"; afiseaza( 1, 1, n ); cout << "vector\n"; for( j = 0; j < n; j++ ) cout << v[j] << " "; cout << "\n";*/ } return rez; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:69:24: warning: unused variable 'j' [-Wunused-variable]
   69 |     int i, l, rez = 0, 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...