Submission #1035337

#TimeUsernameProblemLanguageResultExecution timeMemory
1035337edogawa_somethingArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms604 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vii; typedef pair<int,int> pii; #define pb push_back #define F first #define S second map<int,set<int>>s; ll sz=1; struct segtree{ vii node; void init(ll x){ while(sz<x) sz*=2; node.resize(2*sz); } void update(ll i,ll x=0,ll lx=0,ll rx=sz){ if(rx-lx==1){ node[x]++; return; } int mid=((lx+rx)>>1); if(i<mid) update(i,x*2+1,lx,mid); else update(i,x*2+2,mid,rx); node[x]=node[x*2+1]+node[x*2+2]; } int query(ll l,ll x=0,ll lx=0,ll rx=0){ if(lx>=l) return node[x]; if(rx<=l) return 0; int mid=((lx+rx)>>1); return query(l,x*2+1,lx,mid)+query(l,x*2+2,mid,rx); } }seg; bool vis[300010]; ll count_swaps(vector<int>a) { seg.init(a.size()); for(int i=0;i<a.size();i++) s[a[i]].insert(i); ll ans=0; for(int i=0;i<a.size();i++){ if(vis[i]) continue; auto it=s[-a[i]].upper_bound(i); ll ind=*it+seg.query(*it); ll ii=i+seg.query(i); vis[*it]=1; seg.update(*it); ans+=ind-ii-1; if(a[i]>0) ans++; } return ans; }

Compilation message (stderr)

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