Submission #313013

#TimeUsernameProblemLanguageResultExecution timeMemory
313013hackermubArranging Shoes (IOI19_shoes)C++17
100 / 100
211 ms141424 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fi first #define se second #define pb push_back #define all(v) v.begin(),v.end() #define sz(v) (int)v.size() #define uid uniform_int_distribution<int> //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7; const int64_t INF = 1e18; const int MAXN = 2e5+7; int N; vector<ll> tree(MAXN); void update(int idx,int val=1){ while(idx<=N){ tree[idx]+=val; idx+=idx&(-idx); } } ll read(int idx){ ll sum=0; while(idx>0){ sum+=tree[idx]; idx-=idx&(-idx); } return sum; } ll query(int L,int R){ return read(R)-read(L-1); } long long count_swaps(std::vector<int> s) { N=s.size(); int n=N/2; queue<int> idx[2*n+1]; for(int i=0;i<2*n;i++){ //cout<<s[i]+n<<" "; idx[s[i]+n].push(i+1); } vector<int> perm; vector<bool> vis(2*n+1); for(int i=0;i<2*n;i++)if(!vis[i]){ if(s[i]<0){ perm.pb(i+1); vis[i]=1; perm.pb(idx[-s[i]+n].front()); idx[-s[i]+n].pop(); vis[perm.back()-1]=1; }else{ perm.pb(idx[-s[i]+n].front()); idx[-s[i]+n].pop(); vis[perm.back()-1]=1; perm.pb(i+1); vis[i]=1; } idx[s[i]+n].pop(); } ll ans=0; for(auto x:perm){ ans+=query(x+1,N); update(x); } return ans; } #ifdef OFFLINE int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(); //If you hack my code , You are gay int n; cin>>n; vector<int> s(2*n); for(int i=0;i<2*n;i++){ cin>>s[i]; } cout<<count_swaps(s); return 0; } #endif
#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...