Submission #1021823

#TimeUsernameProblemLanguageResultExecution timeMemory
1021823mindiyakArranging Shoes (IOI19_shoes)C++14
100 / 100
144 ms143400 KiB
#include "shoes.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define fst first #define nl endl #define sec second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; using namespace std; vector<ll> num_swaps(600005,0); ll get_swaps(ll pos,ll l,ll r,ll ql,ll qr){ if(ql > r || qr<l) return 0; if(r<=qr && l>=ql){ // cout << "e " << pos << endl; return num_swaps[pos]; } ll mid = (l+r)/2; return get_swaps(2*pos+1,l,mid,ql,qr) + get_swaps(2*pos+2,mid+1,r,ql,qr); } void update_swaps(ll pos,ll l,ll r,ll index,ll val){ num_swaps[pos] += val; if(index == l && l == r){ return; } ll mid = (l+r)/2; if(index <= mid){ update_swaps(2*pos+1,l,mid,index,val); }else{ update_swaps(2*pos+2,mid+1,r,index,val); } } ll count_swaps(vector<int> s) { vector<deque<ll>> shoes(200005); ll ans = 0; ll n = s.size(); for(ll i = 0;i<s.size();i++){ // cout << "a " << s[i]+100001 << " " << shoes.size() << " " << shoes[s[i]+100001].size() << endl; if(shoes[s[i]+100001].size() > 0){ // cout << "a" << endl; if(s[i]>0)ans--; // cout << "b" << endl; // cout << (s[i]>0) << " " << i << " " << shoes[s[i]+100001][0] << " "; // cout << "c" << endl; // cout << get_swaps(0,0,n-1,shoes[s[i]+100001][0],i) << " "; // cout << "d" << endl; ans += i-shoes[s[i]+100001][0]-get_swaps(0,0,n-1,shoes[s[i]+100001][0],i); // cout << ans << endl; update_swaps(0,0,n-1,i,1); update_swaps(0,0,n-1,shoes[s[i]+100001][0],-1); shoes[s[i]+100001].pop_front(); }else{ shoes[-s[i]+100001].pb(i); } // FOR(j,0,4*n)cout << num_swaps[j] << " "; // cout << endl << endl; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:74:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(ll i = 0;i<s.size();i++){
      |               ~^~~~~~~~~
#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...