Submission #870750

#TimeUsernameProblemLanguageResultExecution timeMemory
870750tuannmArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 2e5 + 1; const string NAME = ""; const int lim = 2147483647; //const unsigned int lim = 4294967295; //const long long lim = 9223372036854775807; //const unsigned long long lim = 18446744073709551615; const int mset = 0x3f; const double pi = acos(-1); int n, a[N]; vector<int> q[2][N]; int perm[N]; long long tree[4 * N]; bool used[N]; void update(int s, int l, int r, int x, int y){ if(x < l || x > r) return; if(l == r){ tree[s] += y; return; } int mid = (l + r) / 2; update(2 * s, l, mid, x, y); update(2 * s + 1, mid + 1, r, x, y); tree[s] = tree[2 * s] + tree[2 * s + 1]; } long long get(int s, int l, int r, int u, int v){ if(l > v || r < u) return 0; if(l >= u && r <= v) return tree[s]; int mid = (l + r) / 2; return get(2 * s, l, mid, u, v) + get(2 * s + 1, mid + 1, r, u, v); } void inp(){ cin >> n; for(int i = 1; i <= 2 * n; ++i){ cin >> a[i]; if(a[i] > 0) q[1][a[i]].pb(i); else q[0][-a[i]].pb(i); } for(int i = 1; i <= n; ++i){ reverse(q[0][i].begin(), q[0][i].end()); reverse(q[1][i].begin(), q[1][i].end()); } } void solve(){ int cnt = 0; for(int i = 1; i <= 2 * n; ++i){ if(used[i]) continue; if(a[i] > 0){ int t0 = q[0][a[i]].back(); int t1 = q[1][a[i]].back(); q[1][a[i]].pop_back(); q[0][a[i]].pop_back(); used[t0] = true; used[t1] = true; perm[t0] = ++cnt; perm[t1] = ++cnt; } else{ int t0 = q[0][-a[i]].back(); int t1 = q[1][-a[i]].back(); q[1][-a[i]].pop_back(); q[0][-a[i]].pop_back(); used[t0] = true; used[t1] = true; perm[t0] = ++cnt; perm[t1] = ++cnt; } } long long ans = 0; for(int i = 1; i <= 2 * n; ++i){ ans += get(1, 1, 2 * n, perm[i] + 1, 2 * n); update(1, 1, 2 * n, perm[i], 1); } cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }

Compilation message (stderr)

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