Submission #468834

#TimeUsernameProblemLanguageResultExecution timeMemory
468834MohamedAliSaidaneArranging Shoes (IOI19_shoes)C++14
100 / 100
323 ms280492 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef vector<int> vi; typedef long long ll; typedef pair<ll,ll> pll; typedef tuple<int,int,int> ti; typedef unsigned long long ull; typedef long double ld; typedef vector<ll> vll; typedef pair<ld,ld> pld; #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front #define ff first #define ss second #define MOD (int)(1e8) #define INF (ll) (1e18) #define all(v) (v).begin(),(v).end() #define LSOne(S) ((S) & -(S)) ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} ld pointdist(ld x, ld y, ld point) { return ((x-point)*(y-point))/abs(x-y); } //ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); } const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+ ////////////******SOLUTION******\\\\\\\\\\\ vll A, st; ll k = 1; ll n; void build(int p, int l, int r) { if(l == r) { st[p] = A[l]; return ; } build(2*p,l,(l+r)/2); build(2*p+1,(l+r)/2+1,r); st[p] = st[2*p] + st[2*p+1]; return ; } ll rsq(ll p, ll l, ll r, ll i, ll j) { if(i > j) return 0; if(l >= i && r <= j) return st[p]; ll mid = (l+r)/2; return rsq(2*p,l,mid,i,min(j,mid)) + rsq(2*p+1,mid+1,r,max(i,mid+1),j); } void update(ll i) { A[i] = 0; i += k; st[i] = 0; i /= 2; while(i) { st[i] = st[2*i] + st[2*i+1]; i /= 2; } } ll count_swaps(vi s) { n= s.size(); while(k < n ) k *= 2; st.assign(2*k+1,0); A.assign(k,0); for(int i = 0; i <k; i ++) A[i] = 1; queue<ll> right[n+1]; queue<ll> left[n+1]; ll ans = 0; build(1,0,k-1); bool seen[n+1]; memset(seen,false,sizeof(seen)); for(ll i= 0; i<n; i ++) { if(s[i] > 0) right[s[i]].push(i); else left[-s[i]].push(i); } for(ll i = 0; i <n; i ++) { if(seen[i]) continue; ll val = abs(s[i]); ll u = 0; if(s[i] > 0) { u = left[val].front(); } else u = right[val].front(); right[val].pop(); left[val].pop(); ans += rsq(1,0,k-1,i,u) - 2; if(s[i] > 0) ans ++; update(u); seen[i] = true; seen[u] = true; } return ans; }

Compilation message (stderr)

shoes.cpp:29:1: warning: multi-line comment [-Wcomment]
   29 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
#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...