Submission #280073

#TimeUsernameProblemLanguageResultExecution timeMemory
280073ec1117Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
/** * Description: range sum queries and point updates for $D$ dimensions * Source: https://codeforces.com/blog/entry/64914 * Verification: SPOJ matsum * Usage: \texttt{BIT<int,10,10>} gives 2D BIT * Time: O((\log N)^D) */ #include "bits/stdc++.h" #include "shoes.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; #define pb push_back #define mp make_pair #define sz(v) ((int)(v).size()) const int MAXN=100000; struct bit{ int tree[MAXN]; void add(int x, int v){ for(int i=x; i<MAXN; i+=i&-i) tree[i] += v; } int query(int x){ int ret = 0; for(int i=x; i; i-=i&-i) ret += tree[i]; return ret; } }bit; int n; vector<pi> order[MAXN]; vector<pi> calc; ll count_swaps(int s[]){ ll ret=0; for(int i=0;i<sizeof(s);i++) order[abs(s[i])].push_back(mp(s[i],i)); for(int i=0;i<MAXN;i++){ sort(order[i].begin(), order[i].end()); for(int j=0;j<order[i].size()/2;j++){ int l = order[i][j].second; int r = order[i][j + sz(order[i])/2].second; if(l>r) { ret++; swap(l,r); } calc.push_back(mp(l+1,r+1)); } } sort(calc.begin(),calc.end()); for(pi x:calc){ int range=bit.query(x.second)-bit.query(x.first); ret+=x.second-x.first-range; bit.add(x.second,-1); bit.add(x.first,-1); } return ret; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(int*)':
shoes.cpp:42:27: warning: 'sizeof' on array function parameter 's' will return size of 'int*' [-Wsizeof-array-argument]
   42 |     for(int i=0;i<sizeof(s);i++)
      |                           ^
shoes.cpp:40:20: note: declared here
   40 | ll count_swaps(int s[]){
      |                ~~~~^~~
shoes.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   42 |     for(int i=0;i<sizeof(s);i++)
      |                 ~^~~~~~~~~~
shoes.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j=0;j<order[i].size()/2;j++){
      |                     ~^~~~~~~~~~~~~~~~~~
/tmp/ccinhkQ2.o: In function `main':
grader.cpp:(.text.startup+0x27a): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status