제출 #1164777

#제출 시각아이디문제언어결과실행 시간메모리
1164777King87arshiaIzbori (COCI22_izbori)C++17
25 / 110
3096 ms18484 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<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx2")

const int N = 2e5 + 5, T = 5000;

vector<int> big;
int ans = 0, n, a[N];
map<int, int> mp;

int main() {
    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        mp[a[i]]++;
    }
    for (auto &[x, y] : mp)
        if (y >= T)
            big.push_back(x);
    ordered_set s;
    for (long long x : big) {
        vector<long long> fake(n + 5, 0);
        int sum = 0;
        for (int i = 0; i < n; i++)
            fake[i] = (a[i] == x ? 1 : -1);
        s.insert({0, -1});
        for (int i = 0; i < n; i++) {
            sum += fake[i];
            ans += i + 1 - s.order_of_key({sum, INT_MIN});
            s.insert({sum, i});
        }
    }
    for (int i = 0; i < n; i++) {
        int mx = 0;
        mp.clear();
        for (int sz = 1; sz <= 2 * T; sz++) {
            if (i + sz - 1 >= n)
                break;
            mp[a[i + sz - 1]]++;
            mx = max(mx, mp[a[i + sz - 1]]);
            if (mx > sz / 2) {
                ans++;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:20:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   20 |     scanf("%lld", &n);
      |            ~~~^   ~~
      |               |   |
      |               |   int*
      |               long long int*
      |            %d
Main.cpp:22:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   22 |         scanf("%lld", &a[i]);
      |                ~~~^   ~~~~~
      |                   |   |
      |                   |   int*
      |                   long long int*
      |                %d
Main.cpp:54:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   54 |     printf("%lld\n", ans);
      |             ~~~^     ~~~
      |                |     |
      |                |     int
      |                long long int
      |             %d
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         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...