Submission #971349

#TimeUsernameProblemLanguageResultExecution timeMemory
971349RandomUserIzbori (COCI22_izbori)C++17
40 / 110
3041 ms5576 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; struct BIT { int n; vector<int> tree; void config(int _n) { n = _n + 10; tree.resize(_n+60); } void update(int p, int v) { for(p++; p<n; p+=p&-p) tree[p] += v; } int query(int p) { int ans = 0; for(p++; p>0; p-=p&-p) ans += tree[p]; return ans; } int query(int l, int r) { return query(r) - query(l-1); } void reset() { for(int &x : tree) x = 0; } }; int32_t main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n; ll ans = 0; cin >> n; vector<int> v(n+1); set<int> s; for(int i=1; i<=n; i++) cin >> v[i], s.insert(v[i]); vector<int> comp(all(s)); BIT bit; bit.config(3*n+5); for(int &x : comp) { int sum = 0; bit.update(n+1, 1); for(int i=1; i<=n; i++) { sum += (v[i] == x); ans += bit.query(2*sum - i - 1 + (n + 1)); bit.update(2*sum - i + (n + 1), 1); } bit.reset(); } cout << ans << '\n'; 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...