Submission #1164397

#TimeUsernameProblemLanguageResultExecution timeMemory
1164397pb2008Izbori (COCI22_izbori)C++20
40 / 110
3094 ms7576 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("03", "ofast", "unroll_loops") const int N = 2e5 + 5, T = 1000; bool mark[N]; long long ans; int n, a[N], cnt[N], seg[N << 3]; void readInput(); void compress(); void pre(); void add(int i); int get(int i); long long calc1(int x); long long calc2(int x); void solve(); void writeOutput(); int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); readInput(); solve(); writeOutput(); return 0; } void readInput() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; } void compress() { vector<pair<int, int>> v; for (int i = 0; i < n; i++) v.push_back({a[i], i}); int tmp = 0; sort(v.begin(), v.end()); for (int i = 0; i < n - 1; i++) a[v[i].second] = tmp, tmp += (v[i].first != v[i + 1].first); a[v[n - 1].second] = tmp; } void pre() { compress(); for (int i = 0; i < n; i++) cnt[a[i]]++; } void add(int i) { for (++i; i <= (n << 1 | 1); i += (i & -i)) seg[i]++; } int get(int i) { int res = 0; for (i; i; i -= (i & -i)) res += seg[i]; return res; } long long calc1(int x) { long long res = 0; for (int len = 1; len <= min(2 * cnt[x], n); len++) { int num = 0; for (int i = 0; i < n; i++) { if (i < len) num += (a[i] == x); else { res += ((len / 2) < num); num += (a[i] == x) - (a[i - len] == x); } } res += ((len / 2) < num); } return res; } long long calc2(int x) { int sum = 0; long long res = 0; memset(seg, 0, sizeof seg); for (int i = 0; i < n; i++) { sum += 1 - 2 * (a[i] != x); res += get(sum + n) + (0 < sum), add(sum + n); } return res; } void solve() { pre(); for (int i = 0; i < n; i++) { if (mark[a[i]]) continue; mark[a[i]] = true; if (cnt[a[i]] < T) ans += calc2(a[i]); else ans += calc2(a[i]); } } void writeOutput() { cout << ans; }

Compilation message (stderr)

Main.cpp:4:51: warning: bad option '-fofast' to pragma 'optimize' [-Wpragmas]
    4 | #pragma GCC optimize("03", "ofast", "unroll_loops")
      |                                                   ^
Main.cpp:4:51: warning: bad option '-funroll_loops' to pragma 'optimize' [-Wpragmas]
Main.cpp:11:16: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   11 | void readInput();
      |                ^
Main.cpp:11:16: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:11:16: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:11:16: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:12:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   12 | void compress();
      |               ^
Main.cpp:12:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:12:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:12:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:13:10: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   13 | void pre();
      |          ^
Main.cpp:13:10: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:13:10: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:13:10: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:14:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   14 | void add(int i);
      |               ^
Main.cpp:14:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:14:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:14:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:15:14: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   15 | int get(int i);
      |              ^
Main.cpp:15:14: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:15:14: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:15:14: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:16:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   16 | long long calc1(int x);
      |                      ^
Main.cpp:16:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:16:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:16:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:17:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   17 | long long calc2(int x);
      |                      ^
Main.cpp:17:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:17:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:17:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:18:12: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   18 | void solve();
      |            ^
Main.cpp:18:12: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:18:12: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:18:12: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:19:18: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   19 | void writeOutput();
      |                  ^
Main.cpp:19:18: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:19:18: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
Main.cpp:19:18: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:21:10: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   21 | int main() {
      |          ^
Main.cpp:21:10: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:29:16: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   29 | void readInput() {
      |                ^
Main.cpp:29:16: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:35:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   35 | void compress() {
      |               ^
Main.cpp:35:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:46:10: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   46 | void pre() {
      |          ^
Main.cpp:46:10: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:52:15: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   52 | void add(int i) {
      |               ^
Main.cpp:52:15: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:57:14: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   57 | int get(int i) {
      |              ^
Main.cpp:57:14: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:64:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   64 | long long calc1(int x) {
      |                      ^
Main.cpp:64:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:81:22: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   81 | long long calc2(int x) {
      |                      ^
Main.cpp:81:22: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:92:12: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
   92 | void solve() {
      |            ^
Main.cpp:92:12: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
Main.cpp:104:18: warning: bad option '-fofast' to attribute 'optimize' [-Wattributes]
  104 | void writeOutput() {
      |                  ^
Main.cpp:104:18: warning: bad option '-funroll_loops' to attribute 'optimize' [-Wattributes]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...