Submission #297378

#TimeUsernameProblemLanguageResultExecution timeMemory
297378shayan_pArranging Shoes (IOI19_shoes)C++17
0 / 100
1 ms288 KiB
#include<bits/stdc++.h> #include "shoes.h" #define F first #define S second #define PB push_back #define sz(s) (int(s.size())) #define bit(n, k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1e5 + 10; int cnt[maxn]; ll sum, sumabs; void add(int pos, int x){ sum-= cnt[pos]; sumabs-= abs(cnt[pos]); cnt[pos]+= x; sum+= cnt[pos]; sumabs+= abs(cnt[pos]); } ll count_swaps(vector<int> a){ ll ans = 0; int POS = 0; for(int x : a){ if(x < 0){ add(cnt[-x], -1); } else{ add(cnt[x], 1); } ll df = sumabs; ans+= sumabs; if(sum & 1){ if(sum == sumabs) ans++, df++; else ans--, df--; } cout << POS << " " << df << endl; POS++; } return ans / 2; }
#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...