Submission #467379

#TimeUsernameProblemLanguageResultExecution timeMemory
467379ChrisGe123Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // template <class T> using Tree = tree<T, null_type, less<T>, // rb_tree_tag, tree_order_statistics_node_update>; const int maxn = 100002; #define mp make_pair #define pb push_back #define f first #define s second const int mod = 1e9+7; typedef pair<int, int> pii; int n; int shoes[2*maxn]; // for each shoe, we need the closest shoe to the right that is the opposite pair to it int r[2*maxn]; vector<int> eachsize[2*maxn]; //eachsize[i] contains the positions of the shoes of size i-n in order int sizepos[2*maxn]; //sizepos[i] tells us how many shoes of size i-n we've seen int fentree[2*maxn]; /* We need to figure out using some PURS thing how to get the number of elements between i and r[i] that have already been taken care of we can do this by just making a BIT where initially everything is 1, and then if the element i has been used, we make BIT[i] = 0 */ int lsb(int a) { return a & -a; } void change(int a, int c) { while (a <= 2*n) { fentree[a] += c; a += lsb(a); } } int sum(int a) { int s = 0; while (a > 0) { s += fentree[a]; a -= lsb(a); } return s; } void setupIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() { //setupIO("arrangeshoes"); ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i=1; i<=2*n; i++) { cin >> shoes[i]; eachsize[shoes[i]+n].pb(i); } for (int i=1; i<=2*n; i++) { if (sizepos[shoes[i]+n] < (int) eachsize[-shoes[i]+n].size()) { int temp = eachsize[-shoes[i]+n][sizepos[shoes[i]+n]]; if (temp > i) { r[i] = temp; } } sizepos[shoes[i]+n]++; } ll ans = 0; for (int i=1; i<=2*n; i++) { change(i, 1); } for (int i=1; i<=2*n; i++) { if (r[i] != 0) { if (r[i] != i+1) { ans += sum(r[i]-1) - sum(i); //cerr << sum(r[i]-1) << " " << sum(i) << endl; } if (shoes[i] > 0) { ans++; } change(r[i], -1); } } cout << ans << endl; }

Compilation message (stderr)

shoes.cpp: In function 'void setupIO(std::string)':
shoes.cpp:58:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shoes.cpp:59:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  freopen((s + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccG8AA4u.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc37ttIx.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccG8AA4u.o: in function `main':
grader.cpp:(.text.startup+0x29d): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status