제출 #1047433

#제출 시각아이디문제언어결과실행 시간메모리
1047433NotLinuxArranging Shoes (IOI19_shoes)C++17
45 / 100
37 ms3584 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() const long long inf = 1e18 + 7; struct SEGT{ vector < int > t; int tree_size; const int identity_element = 0; int merge(int x , int y){ return x + y; } void init(int x){ tree_size = x+3; t.assign(2*tree_size , identity_element); } void modify(int p, int value) { // set value at position p for (t[p += tree_size] = value; p > 1; p >>= 1){ t[p>>1] = merge(t[p] , t[p^1]); } } int query(int l, int r) { // sum on interval [l, r] int res = identity_element; for (r+=1 , l += tree_size, r += tree_size; l < r; l >>= 1, r >>= 1) { if (l&1) res = merge(res , t[l++]); if (r&1) res = merge(res , t[--r]); } return res; } }; long long count_swaps(vector<int> s) { int n = sz(s) / 2; long long ans = 0; SEGT segt; segt.init(2 * n + 5); int sayac0 = 1 , sayac1 = 2; for(int i = 0;i<2*n;i++){ if(s[i] < 0){ ans += segt.query(sayac0 , 2*n); segt.modify(sayac0 , 1); sayac0+=2; } else{ ans += segt.query(sayac1 , 2*n); segt.modify(sayac1 , 1); sayac1+=2; } } return ans; }
#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...