Submission #847435

#TimeUsernameProblemLanguageResultExecution timeMemory
847435AmaarsaaArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; using ll = long long; ll Sum[800005], mid; void Change(ll p, ll lo, ll hi, ll x) { if ( lo== hi) { Sum[x] = 1; return ; } mid = (lo + hi)/2; if ( x <= mid) Change(2 * p, lo, mid, x); else Change(2 * p + 1, mid + 1, hi, x); Sum[p] = Sum[2 * p] + Sum[2 * p + 1]; } ll Find(ll p, ll lo, ll hi, ll st, ll fn) { if ( st > hi || lo > fn) return 0; if ( st <= lo && hi <= fn) { return Sum[p]; } mid = (lo + hi)/2; return Find(2 * p, lo, mid, st, fn) + Find(2 * p + 1, mid + 1, hi, st, fn); } long long count_swaps(std::vector<int> s) { ll n, i, p, m; n = s.size(); int Used[100005]; queue < int > Left[n + 2], Right[n + 2]; for (i = 0; i < s.size(); i ++) { cout << s[i] << " "; if ( s[i] < 0) { Left[-s[i]].push(i); } else Right[s[i]].push(i); } long long ans =0; for (i = 0; i < s.size(); i ++) { if ( Used[i] == 1) continue; p = s[i]; if ( p < 0) { m= Right[-p].front(); Used[m]= 1; m = m + Find(1, 0, n - 1, m, n - 1); ans += (m - i - 1); Right[-p].pop(); } else { cout << p << " " << Left[p].size() << endl; m= Left[p].front(); Used[m]= 1; m = m + Find(1, 0, n - 1, m, n - 1); ans += (m - i ); Left[-p].pop(); } } return ans; } int main() { ll n, i, x; vector < int > V; cin >> n; for (i = 1; i <= n; i ++) { cin >> x; V.push_back(x); } cout << count_swaps(V) << endl; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:33:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (i = 0; i < s.size(); i ++) {
      |              ~~^~~~~~~~~~
shoes.cpp:41:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (i = 0; i < s.size(); i ++) {
      |              ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cc0GEcwK.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFFN0eI.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status