제출 #298837

#제출 시각아이디문제언어결과실행 시간메모리
298837Aldas25Arranging Shoes (IOI19_shoes)C++14
50 / 100
493 ms297648 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; const int MAXN = 100100; ll fen[MAXN]; void upd (int p, ll x) { p++; for (int i = p; i < MAXN; i += i&(-i)) fen[i] += x; } ll get (int p) { p++; ll ret = 0ll; for (int i = p; i > 0; i -= i&(-i)) ret += fen[i]; return ret; } ll get (int le, int ri) { return get(ri) - get(le-1); } map<int, queue<int>> q; long long count_swaps(std::vector<int> s) { int n = (int)s.size(); FOR(i, 0, n-1) upd(i, 1); FOR(i, 0, n-1) q[s[i]].push(i); ll ret = 0; FOR(i, 0, n-1) { if (get(i,i) == 0) continue; q[s[i]].pop(); int id = q[-s[i]].front(); q[-s[i]].pop(); if (s[i] > 0) ret++; upd (i, -1); upd (id, -1); ret += get(i, id); } return ret; } /* 2 2 1 -1 -2 ans: 4 3 -2 2 2 -2 -2 2 ans: 1 */
#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...