A simpler solution/code for question 2131F - Unjust Binary Life {Question F unjust binary life}.
Essentially the same concept but an easier implementation without the minimum to average part 356146228
/** /> フ | _ _| /`ミ _x ノ / | / ヽ ? / ̄| | | | | ( ̄ヽ__ヽ_)_) \二つ **/ #include <bits/stdc++.h> using namespace std; #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>,__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; #define int long long #define vi vector<long long> #define vpi vector<pair<long long ,long long>> #define msi multiset <long long> #define msp multiset < pair<long long ,long long>> #define si set <long long> #define sp set < pair<long long ,long long>> #define mp map<long long ,long long> #define all(v) v.begin() , v.end() #define frieren for(int i = 0; i < n ; i++) #define s(v) sort(all(v)) int n,k,q ,m , testcase = 1; string s; void vi_in(vi &v, int l = n); int ceill(int a , int b); void test(); void solve() { cin >> n ; cin >> s ; vi a , b ; frieren { a.push_back((s[i] == '1' ) ? 1 : 0 ); } cin >> s; frieren { b.push_back((s[i] == '1' ) ? 1 : 0 ); } int out = 0 ; auto f =[&](vi a , vi b)-> int { int res =0 ; vi zc , oc ; zc.push_back(0); oc.push_back(0); frieren { zc.push_back(zc.back() + (a[i] == 0)); oc.push_back(oc.back() + (a[i] == 1)); } vi ps (n + 1 , 0); frieren { ps[i + 1] = ps[i] + ((b[i] == 0) ? 1 : -1 ); } int o = n ; vi f( 2* n + 1 , 0); for(int i {n} ; i; i--){ f[o + ps[i]]++; } for(auto i{0} ; i < f.size() - 1 ; i++){ f[i + 1] += f[i]; } frieren { int ze = zc[i + 1]; int on = oc[i + 1]; int delta = ze - on ; int zmul , omul ; zmul = f[o -delta]; omul = f.back(); omul -= zmul ; res += ze * zmul ; res += on * omul ; } return res ; }; out = 0 ; out += f(a , b); out += f( b , a); cout << out << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); test(); // solve(); return 0; } void test(){ cin >> testcase; while (testcase--) { solve(); } } void vi_in(vi &v, int l) { for (int i = 0; i < l; i++) { int x ; cin >> x ; v.push_back(x);; } } int ceill(int a , int b){ if(a%b) return a/b + 1; return a/b; }
A simpler solution/code for question 2131F - Unjust Binary Life {Question F unjust binary life}.
Essentially the same concept but an easier implementation without the minimum to average part 356146228
Code