Submission #1156979

#TimeUsernameProblemLanguageResultExecution timeMemory
1156979at128Arranging Shoes (IOI19_shoes)C++20
65 / 100
1096 ms35848 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef tree< int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; #define all(v) ((v).begin()), ((v).end()) #define sz(v) ((int)((v).size())) #define pb push_back typedef long long ll; long long count_swaps(std::vector<int> s1) { int n; n=s1.size()/2; vector<int>v(2*n); map<int,set<int>>m; for(int i=0;i<2*n;i++){ v[i]=s1[i]; m[v[i]].insert(i); } ll res=0,c=0; ordered_set s; for(int i=0;i<2*n;i++){ if(v[i]==INT_MAX){ continue; } c++; if(v[i]>0){ int j=*m[-v[i]].begin(); v[j]=INT_MAX; ll p1=s.size()-s.order_of_key(i); ll p2=s.size()-s.order_of_key(j); s.insert(j); debug(i,j,p1,p2,s); m[-v[i]].erase(m[-v[i]].begin()); debug((j-i-(p1-p2))); res+=max(0ll,(j-i-(p1-p2))); }else{ int j=*m[-v[i]].begin(); v[j]=INT_MAX; ll p1=s.size()-s.order_of_key(i); ll p2=s.size()-s.order_of_key(j); debug(p1,p2); s.insert(j); m[-v[i]].erase(m[-v[i]].begin()); debug((j-i-(p1-p2))-1); res+=max(0ll,(j-i-(p1-p2)-1)); } m[v[i]].erase(i); } return res; }
#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...