Submission #1166094

#TimeUsernameProblemLanguageResultExecution timeMemory
1166094King87arshiaIzbori (COCI22_izbori)C++17
40 / 110
3095 ms16088 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<long long, long long>, null_type, less<pair<long long, long long>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #pragma GCC optimize ("Ofast,unroll-loops") #pragma GCC target ("avx2") const long long N = 2e5 + 5, T = 500; vector<long long> big; long long ans = 0, n, a[N]; unordered_map<long long, long long> mp, mp2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); scanf("%lld", &n); for (long long i = 0; i < n; i++) { scanf("%lld", &a[i]); mp[a[i]]++; } for (auto &[x, y] : mp) if (y >= T) big.push_back(x); for (long long x : big) { ordered_set s; long long fake[n + 5]; long long sum = 0; for (long long i = 0; i < n; i++) fake[i] = (a[i] == x ? 1 : -1); s.insert({0, -1}); for (long long i = 0; i < n; i++) { sum += fake[i]; ans += s.order_of_key({sum, INT_MIN}); s.insert({sum, i}); } } for (long long i = 0; i < n; i++) { pair<long long, long long> mx = {0, 0}; mp2.clear(); for (long long sz = 1; sz <= 2 * T; sz++) { if (i + sz - 1 >= n) break; mp2[a[i + sz - 1]]++; long long x = mp2[a[i + sz - 1]]; if (mx.first < x) mx = {x, a[i + sz - 1]}; if (mx.first * 2 > sz && mp[mx.second] < T) ans++; } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%lld", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...