제출 #158385

#제출 시각아이디문제언어결과실행 시간메모리
158385nickmet2004Arranging Shoes (IOI19_shoes)C++14
10 / 100
191 ms135064 KiB
#include<bits/stdc++.h> //#include<shoes.h> using namespace std; const int NAX = 1e5 + 5; int N; // fenwick tree to count range sums (+0 , +1 , +2) int f[2 * NAX + 1]; void update(int idx , int u){ ++idx; while(idx <= N){ f[idx] += u; idx += idx & (-idx); } } long long sum(int idx){ long long sum = 0; ++idx; while(idx){ sum += f[idx]; idx -= idx & (-idx); } return sum; } // 0 - negative x's , 1 - positive x's queue<int> q[NAX][2]; long long count_swaps(vector<int> S){ N = S.size(); long long ans = 0; // update BIT for(int i = 0; i < N; ++i){ update(i , 1); } for(int i = 0; i < N; ++i){ int x = abs(S[i]); int k = S[i]; int f , d; if(S[i] > 0){ // opposite d = 0; // its f = 1; } else { d = 1; f = 0; } // when queue is empty if(!q[x][d].empty()){ //cerr << sum(i) << " sum(i) " << endl << sum(q[x][d].front() - 1) << "sum(qFRONT())" << endl; ans += (sum(i) - sum(q[x][d].front() - 1) - 1); //cerr << "ans: " << ans << "tavdapirvelad" << endl; if(k > 0){ --ans; //cerr << "ans: " << ans << " sabolood" << endl; update(q[x][d].front() , -1); update(i - 1, 1); q[x][d].pop(); } else { update(i , -1); update(q[x][d].front() , 1); q[x][d].pop(); } } else { q[x][f].push(i); } } return ans; }
#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...