Submission #673143

#TimeUsernameProblemLanguageResultExecution timeMemory
673143KiriLL1caIzbori (COCI22_izbori)C++17
40 / 110
3079 ms7876 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pw(x) (1ll << x) #define sz(x) (int)((x).size()) #define pb push_back #define endl '\n' #define mp make_pair #define vec vector using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef unsigned long long ull; template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; struct fen { vector <int> t; int norm; fen (int n = 0) : norm(n >> 1), t(n + 100) {} inline void upd (int i, int x) { for (i += norm; i < sz(t); i += (i & -i)) t[i] += x; } inline int get (int i) { int res = 0; for (i += norm; i; i -= (i & -i)) res += t[i]; return res; } inline int get (int l, int r) { return get(r) - get(l - 1); } }; inline void solve () { int n; cin >> n; vector <int> a (n + 1); for (int i = 1; i <= n; ++i) cin >> a[i], --a[i]; map <int, vector <int>> mp; for (int i = 1; i <= n; ++i) mp[a[i]].pb(i); const int N = n * 4 + 100; const int B = 0; ll ans = 0; /// O(n^2) ! test for (auto &[_, pos] : mp) { if (sz(pos) > B) { vector <int> c (n + 1); fen t (N); t.upd(0, 1); for (int i = 1; i <= n; ++i) c[i] = c[i - 1] + (a[i] == _ ? +1 : 0); for (int i = 1; i <= n; ++i) { ans += t.get(2 * c[i] - i - 1); t.upd(2 * c[i] - i, 1); } } else { } } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

Main.cpp: In constructor 'fen::fen(int)':
Main.cpp:33:13: warning: 'fen::norm' will be initialized after [-Wreorder]
   33 |         int norm;
      |             ^~~~
Main.cpp:32:22: warning:   'std::vector<int> fen::t' [-Wreorder]
   32 |         vector <int> t;
      |                      ^
Main.cpp:34:9: warning:   when initialized here [-Wreorder]
   34 |         fen (int n = 0) : norm(n >> 1), t(n + 100) {}
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...