Submission #589776

#TimeUsernameProblemLanguageResultExecution timeMemory
589776shrimbArranging Shoes (IOI19_shoes)C++17
100 / 100
389 ms285348 KiB
#include"bits/stdc++.h" using namespace std; #include "shoes.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; long long count_swaps(std::vector<int> s) { int n = s.size(); int a[n]; int b[n]; int c[n]; int d[n]; memset(d, 0, sizeof d); queue<int> p[n + 1]; stack<int> p2[n + 1]; for (int i = 0 ; i < n ; i++) { if (s[i] > 0) p[s[i]].push(i); else p2[-s[i]].push(i); } int cnt = 0, cnt2 = 0; for (int i = 0 ; i < n ; i++) { if (s[i] < 0) { c[cnt] = i; a[i] = cnt++; c[cnt] = p[-s[i]].front(); a[p[-s[i]].front()] = cnt++; p[-s[i]].pop(); } } cnt = 0; for (int i = 0 ; i < n ; i++) { if (d[i]) continue; if (a[i] & 1) { b[i] = cnt + 1; b[c[a[i] - 1]] = cnt; cnt += 2; } else { b[i] = cnt; b[c[a[i] + 1]] = cnt + 1; cnt += 2; } } long long ret = 0; ordered_set<int> os; for (int i = n - 1 ; i >= 0 ; i--) { ret += os.order_of_key(b[i]); os.insert(b[i]); } return ret; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:29:15: warning: unused variable 'cnt2' [-Wunused-variable]
   29 |  int cnt = 0, cnt2 = 0;
      |               ^~~~
#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...