Submission #305995

#TimeUsernameProblemLanguageResultExecution timeMemory
305995kylych03Arranging Shoes (IOI19_shoes)C++14
10 / 100
125 ms25304 KiB
#include "shoes.h" #include <bits/stdc++.h> //#include "grader.cpp" using namespace std; long long res[200010]; int vis[200011], dp[200010]; vector <int> a1[100002], b[100002]; const int maxn=2e3+7; vector<int> a; vector<int> t(4*maxn); vector<int> add(4*maxn,0); void push(int v) { if(add[v]) { add[v*2]+=add[v]; add[v*2+1]+=add[v]; add[v]=0; } } void build(int v,int tl,int tr) { if(tl==tr) { t[v]=a[tl]; } else { int tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); } } int get(int v,int tl,int tr,int pos) { if(tl==tr) { t[v]+=add[v]; add[v]=0; return t[v]; } else { int tm=(tl+tr)/2; push(v); if(pos<=tm) { return get(v*2,tl,tm,pos); } else { return get(v*2+1,tm+1,tr,pos); } } } void Add(int v,int tl,int tr,int l,int r,int val) { if(l>r) { return; } if(tl==l && tr==r) { add[v]+=val; return; } else { int tm=(tl+tr)/2; Add(v*2,tl,tm,l,min(r,tm),val); Add(v*2+1,tm+1,tr,max(tm+1,l),r,val); } } long long count_swaps(std::vector<int> s) { long long sum = 0; for(int i = 0 ; i < s.size(); i++){ if(s[i]>0) a1[s[i]].push_back(i); else b[abs(s[i])].push_back(i); } for(int i = 0 ; i <100001;i++){ for(int j = 0 ; j < a1[i].size();j++){ dp[a1[i][j]]=b[i][j]; dp[b[i][j]]=a1[i][j]; } } int n = s.size()+1; for(int i = 0 ; i < s.size(); i++){ if(vis[i]==1) continue; int j=i+1; Add(1,0,n,i+1,dp[i]+1,1); sum += dp[i] - i - 1 + get(1,0,n-1,dp[i]) - get(1,0,n-1,i+1); if(s[i] > 0) sum++; vis[dp[i]]=1; } return sum; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0 ; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
shoes.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int j = 0 ; j < a1[i].size();j++){
      |                         ~~^~~~~~~~~~~~~~
shoes.cpp:95:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i = 0 ; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
shoes.cpp:99:13: warning: unused variable 'j' [-Wunused-variable]
   99 |         int j=i+1;
      |             ^
#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...