Submission #533582

#TimeUsernameProblemLanguageResultExecution timeMemory
533582topovikIzbori (COCI22_izbori)C++14
40 / 110
3056 ms31664 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define s second using namespace std; typedef long long ll; typedef long double ld; const ll oo = 1e18 + 7; const ll N = 5e5 + 10; const ll N1 = 5e6; const ll M = 2e3 + 10; vector <ll> ps[N]; ll b[N]; map <ll, ll> mp; ll ans = 0; int val[N]; int key[N]; int t; int main() { ios_base::sync_with_stdio(0); iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; ll a[n]; vector <ll> cmp; for (ll i = 0; i < n; i++) cin >> a[i], cmp.pb(a[i]); sort(cmp.begin(), cmp.end()); cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin()); for (ll i = 0; i < n; i++) a[i] = lower_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin(); for (ll i = 0; i < n; i++) ps[a[i]].pb(i); for (ll i = 0; i < n; i++) { t++; int nom_mx = N - 1; for (int j = i; j < min(n, i + M); j++) { if (key[a[j]] != t) { key[a[j]] = t; val[a[j]] = 0; } val[a[j]]++; if (val[a[j]] > val[nom_mx]) nom_mx = a[j]; if (val[nom_mx] * 2 > (j - i + 1)) { if (ps[nom_mx].size() <= M / 2) ans++; } } } for (ll i = 0; i < n; i++) if (ps[i].size() > M / 2) { for (ll j = 0; j < n; j++) b[j] = 0; for (auto j : ps[i]) b[j] = 1; mp.clear(); ll sum1 = 0; ll kol = 0; for (ll j = 0; j < n; j++) { sum1 += b[j]; mp[sum1 * 2 - (j + 1)]++; if (sum1 * 2 - (j + 1) > 0) kol++; } ans += kol; ll c = 1; sum1 = 0; for (ll j = 0; j < n; j++) { sum1 += b[j]; mp[sum1 * 2 - (j + 1)]--; if (sum1 * 2 - (j + 1) >= c) kol--; if (b[j] == 0) { c--; kol += mp[c]; } else { kol -= mp[c]; c++; } ans += kol; } cout << endl; } cout << ans; } /* 5 3 2 1 1 2 2 3 2 3 3 4 4 5 4 1 1 2 2 3 3 4 4 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...