Submission #387452

#TimeUsernameProblemLanguageResultExecution timeMemory
387452ismoilovArranging Shoes (IOI19_shoes)C++14
50 / 100
1096 ms35180 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define rall(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fv(c) for(int (a) = (1); (a) <= (c); (a)++) #define fz(c) for(int (a) = (0); (a) < (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define pb push_back #define in insert #define ss second #define ff first struct ftree { vector <int> bit; ftree(int n){ bit = vector<int> (n+1); } void add(int k, int x){ k ++; while(k < (int)bit.size()){ bit[k] += x; k += k & -k; } } int sum(int k) { int ans = 0; k ++; while(k){ ans += bit[k]; k -= k & -k; } return ans; } }; ll count_swaps(vector <int> s) { ftree Ftree(s.size()); map<int, vector<int>> m; set<int> c; fp(i,0,s.size()){ c.in(i); m[s[i]].pb(i); Ftree.add(i, 1); } ll ans = 0; while(!c.empty()){ int x = *c.begin(); c.erase(c.begin()); m[s[x]].erase(m[s[x]].begin()); int y = *m[-s[x]].begin(); m[-s[x]].erase(m[-s[x]].begin()); Ftree.add(x, -1); Ftree.add(y, -1); c.erase(y); int g = Ftree.sum(y); if(s[x] > 0) g ++; ans += g; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:10:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
shoes.cpp:53:2: note: in expansion of macro 'fp'
   53 |  fp(i,0,s.size()){
      |  ^~
shoes.cpp:10:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                                      ~~~~^~~~~
shoes.cpp:53:2: note: in expansion of macro 'fp'
   53 |  fp(i,0,s.size()){
      |  ^~
#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...