Submission #306030

#TimeUsernameProblemLanguageResultExecution timeMemory
306030kylych03Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include <bits/stdc++.h> #include "grader.cpp" using namespace std; long long res[200010]; long long vis[200011], dp[200010]; vector <long long> a1[100002], b[100002]; const long long maxn=2e5+7; vector<long long> a; vector<long long> t(4*maxn); vector<long long> add(4*maxn,0); void push(long long v) { if(add[v]) { add[v*2]+=add[v]; add[v*2+1]+=add[v]; add[v]=0; } } void build(long long v,long long tl,long long tr) { if(tl==tr) { t[v]=a[tl]; } else { long long tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); } } long long get(long long v,long long tl,long long tr,long long pos) { if(tl==tr) { t[v]+=add[v]; add[v]=0; return t[v]; } else { long long 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(long long v,long long tl,long long tr,long long l,long long r,long long val) { if(l>r) { return; } if(tl==l && tr==r) { add[v]+=val; return; } else { long long 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(long long 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(long long i = 0 ; i <100001;i++){ for(long long j = 0 ; j < a1[i].size();j++){ dp[a1[i][j]]=b[i][j]; dp[b[i][j]]=a1[i][j]; } } long long n = s.size()+1; for(long long i = 0 ; i < s.size(); i++){ if(vis[i]==1) continue; long long j=i+1; sum += dp[i] - i - 1 + get(1,0,n-1,dp[i]) - get(1,0,n-1,i); Add(1,0,n,i,dp[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:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:89:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(long long j = 0 ; j < a1[i].size();j++){
      |                               ~~^~~~~~~~~~~~~~
shoes.cpp:95:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:99:19: warning: unused variable 'j' [-Wunused-variable]
   99 |         long long j=i+1;
      |                   ^
/tmp/ccwCoYL1.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccyIWdxd.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status