제출 #426632

#제출 시각아이디문제언어결과실행 시간메모리
426632salehArranging Shoes (IOI19_shoes)C++17
100 / 100
822 ms158096 KiB
#include "shoes.h"// #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #define ft first #define sd second using namespace std; using namespace __gnu_pbds; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int MAXN = 100 * 1000 + 23; map<int, deque<int>> v; ordered_set t; vector<pii> vec; long long count_swaps(vector<int> s) { int n = s.size() / 2, cnt = 0, a[MAXN << 1]; long long ans = 0; for (int i = 0; i < (n << 1); i++) { v[s[i]].push_back(i); if (!v[-s[i]].empty()) { if (s[i] > 0) vec.push_back({v[-s[i]].front(), i}); else vec.push_back({i, v[-s[i]].front()}); v[s[i]].pop_back(); v[-s[i]].pop_front(); } } // for (auto i : vec) cout << i.ft << ' ' << i.sd << endl; sort(vec.begin(), vec.end(), [](pii x, pii y) { return x.ft + x.sd < y.ft + y.sd; }); for (auto i : vec) { // cout << i.ft << ' ' << i.sd << endl; a[i.ft] = cnt++; a[i.sd] = cnt++; } for (int i = 0; i < (n << 1); i++) { // cout << a[i] << ' '; ans += t.size() - t.order_of_key(a[i]); t.insert(a[i]); } //cout << endl; return ans; } //int main() {cout << count_swaps({2, 1, -1, -2});}//
#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...