Submission #643666

#TimeUsernameProblemLanguageResultExecution timeMemory
643666_petar_bArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include <cstdio> #include <cassert> using namespace std; //#include "shoes.h" #include <bits/stdc++.h> #define MAXN 200010 #define DELTA 100001 #define pb push_back #define ll long long #define fi first #define se second #define mp make_pair //using namespace std; int n, t[4*MAXN], par[MAXN], tleaf[MAXN]; queue<int> posOf[MAXN]; void build(int v, int tl, int tr) { if (tl == tr) t[v] = 1; else { int tm = (tl + tr) / 2; build(v*2, tl, tm); build(v*2+1, tm+1, tr); t[v] = t[v*2] + t[v*2+1]; } } int sum(int v, int tl, int tr, int l, int r) { if (l > r) return 0; if (l == tl && r == tr) return t[v]; int tm = (tl + tr) / 2; return sum(v*2, tl, tm, l, min(r, tm)) + sum(v*2+1, tm+1, tr, max(l, tm+1), r); } void update(int v, int tl, int tr, int pos) { if (tl == tr) t[v] = 0; else { int tm = (tl + tr) / 2; if (pos <= tm) update(v*2, tl, tm, pos); else update(v*2+1, tm+1, tr, pos); t[v] = t[v*2] + t[v*2+1]; } } long long count_swaps(std::vector<int> s) { n = s.size(); for (int i = 0; i < n; i++) { tleaf[i] = 1; int other = DELTA - s[i]; if (!posOf[other].empty()) { par[i] = posOf[other].front(); posOf[other].pop(); } else { par[i] = -1; posOf[s[i]+DELTA].push(i); } } build(1, 0, n-1); int res = 0; for (int i = n-1; i >= 0; i--) { if (tleaf[i] == 1) { res += sum(1, 0, n-1, par[i]+1, i-1); tleaf[par[i]] = 0; update(1, 0, n-1, par[i]); if (s[i] < 0) res++; } } return res; } int main() { int n; assert(1 == scanf("%d", &n)); vector<int> S(2 * n); for (int i = 0; i < 2 * n; i++) assert(1 == scanf("%d", &S[i])); fclose(stdin); long long result = count_swaps(S); printf("%lld\n", result); fclose(stdout); return 0; } /* 2 2 1 -1 -2 3 -2 2 2 -2 -2 2 */

Compilation message (stderr)

/usr/bin/ld: /tmp/ccufpq7m.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccxJhlCk.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status