Submission #632746

#TimeUsernameProblemLanguageResultExecution timeMemory
632746ghostwriterArranging Shoes (IOI19_shoes)C++14
100 / 100
74 ms20336 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Practising for VOI23 gold medal */ const int N = 2e5 + 1; int n, c[N], f[N]; vi d[N], d1[N]; int get(int ps) { ++ps; int rs = 0; for (int i = ps; i >= 1; i -= (i & -i)) rs += f[i]; return rs; } void upd(int ps, int v) { ++ps; for (int i = ps; i <= n + 1; i += (i & -i)) f[i] += v; } long long count_swaps(std::vector<int> s) { n = sz(s) - 1; FOS(i, n, 0) if (s[i] < 0) d[-s[i]].pb(i); else d1[s[i]].pb(i); ll rs = 0; FOR(i, 0, n) { if (c[i]) continue; int ss = abs(s[i]); if (s[i] < 0) { int pos = d1[ss].back(); c[pos] = 1; d1[ss]._pb(); rs += pos - i - 1 - get(pos) + get(i); d[ss]._pb(); upd(pos, 1); } else { int pos = d[ss].back(); c[pos] = 1; d[ss]._pb(); rs += pos - i - get(pos) + get(i); d1[ss]._pb(); upd(pos, 1); } } return rs; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
shoes.cpp:44:2: note: in expansion of macro 'FOS'
   44 |  FOS(i, n, 0)
      |  ^~~
shoes.cpp:25:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   25 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
shoes.cpp:48:2: note: in expansion of macro 'FOR'
   48 |  FOR(i, 0, n) {
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...