제출 #980127

#제출 시각아이디문제언어결과실행 시간메모리
980127ShaShiArranging Shoes (IOI19_shoes)C++17
50 / 100
128 ms137808 KiB
#include "shoes.h" #include <bits/stdc++.h> #define F first #define S seond #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define pii pair<int, int> using namespace std; typedef long long ll; const int MAXN = (int)1e5 + 7; const int MOD = 998244353; const int INF = (int)1e9 + 7; int n, m, t, tmp, tmp2, tmp3, u, v, w, ans; deque<int> vec[2][MAXN]; /* BIT */ int fen[MAXN]; inline void upd(int x, int y) { for (x++; x<MAXN; x+=x&-x) fen[x] += y; } inline int get(int x) { int res = 0; for (x++; x>0; x-=x&-x) res += fen[x]; return res; } /* BIT */ ll count_swaps(vector<int> s) { n = s.size()/2; ll ans = 0; for (int i=0; i<2*n; i++) { upd(i, 1); if (s[i] < 0) vec[0][0-s[i]].pb(i); else vec[1][s[i]].pb(i); } for (int j=0; j<2*n; j++) { if (get(j)-get(j-1) == 0) continue; if (s[j] < 0) { tmp2 = vec[1][0-s[j]].front(); vec[1][0-s[j]].pop_front(); vec[0][0-s[j]].pop_front(); // cout << "@" << s[j] << " " << s[tmp2] << endl; // cout << "!" << get(tmp2-1) << " " << get(j) << endl; ans += get(tmp2-1)-get(j); upd(tmp2, -1); } else { tmp2 = vec[0][s[j]].front(); vec[1][s[j]].pop_front(); vec[0][s[j]].pop_front(); // cout << "@" << s[j] << " " << s[tmp2] << endl; // cout << "!" << get(tmp2) << " " << get(j) << endl; ans += get(tmp2)-get(j); upd(tmp2, -1); } upd(j, -1); } return ans; } // int main() { // int n; // assert(1 == scanf("%d", &n)); // vector<int> S(2 * n); // for (int i = 0; i < 2 * n; i++) // assert(1 == scanf("%d", &S[i])); // fclose(stdin); // long long result = count_swaps(S); // printf("%lld\n", result); // fclose(stdout); // return 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...