답안 #1104490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104490 2024-10-24T00:31:42 Z Whisper Izbori (COCI22_izbori) C++17
110 / 110
595 ms 11984 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }

#define MAX             200005
#define BLOCK_SIZE      444
#define off_set         200000

int nArr;
int A[MAX];

vector<int> pos[MAX];


template<class T = vector<int>>
    T unique (T v){
        sort(v.begin(), v.end());
        v.resize(unique(v.begin(), v.end()) - v.begin());
        return v;
    }

template<class T = int>
    T find(T x, const vector<int>& v){
        return (int)(lower_bound(v.begin(), v.end(), x) - v.begin() + 1);
    }

bool hvy[MAX];
int cnt[MAX];
struct custom_hash{
    size_t operator ()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

int g[MAX];
void process(void){
    cin >> nArr;
    vector<int> comp;
    for (int i = 1; i <= nArr; ++i) cin >> A[i], comp.push_back(A[i]);
    comp = unique(comp);
    for (int i = 1; i <= nArr; ++i) A[i] = find(A[i], comp), cnt[A[i]]++;
    for (int i = 1; i <= nArr; ++i) {
        hvy[i] = (cnt[i] >= BLOCK_SIZE);
    }
    long long ans = 0;
    for (int l = 1; l <= nArr; ++l){
        int max_occurence = 0;
        for (int r = l; r <= nArr && (r - l + 1 < 2 * BLOCK_SIZE); ++r){
            if(hvy[A[r]]) continue;
            g[A[r]]++;
            maximize(max_occurence, g[A[r]]);
            if (2 * max_occurence > (r - l + 1)) ++ans;
        }
        for (int r = l; r <= nArr && (r - l + 1 < 2 * BLOCK_SIZE); ++r){
            if(!hvy[A[r]]) --g[A[r]];
        }
    }
    for (int i = 1; i <= nArr; ++i){
        if (!hvy[i]) continue;
        vector<int> cnt(2 * nArr + 1);
        int pref = nArr, sm = 0;
        cnt[pref]++;
        for (int j = 1; j <= nArr; ++j){
            int value = (A[j] == i ? 1 : -1);
            pref += value;
            if(value > 0){
                sm += cnt[pref - 1];
            }
            else{
                sm -= cnt[pref];
            }
            ans += sm;
            cnt[pref]++;
        }
    }
    cout << ans;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6756 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6756 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 6 ms 6736 KB Output is correct
10 Correct 5 ms 6736 KB Output is correct
11 Correct 5 ms 6736 KB Output is correct
12 Correct 6 ms 6736 KB Output is correct
13 Correct 5 ms 6776 KB Output is correct
14 Correct 5 ms 6736 KB Output is correct
15 Correct 5 ms 6736 KB Output is correct
16 Correct 5 ms 6736 KB Output is correct
17 Correct 5 ms 6780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 8892 KB Output is correct
2 Correct 331 ms 9856 KB Output is correct
3 Correct 190 ms 8648 KB Output is correct
4 Correct 368 ms 9980 KB Output is correct
5 Correct 353 ms 10068 KB Output is correct
6 Correct 379 ms 10192 KB Output is correct
7 Correct 381 ms 10164 KB Output is correct
8 Correct 408 ms 10372 KB Output is correct
9 Correct 392 ms 10164 KB Output is correct
10 Correct 400 ms 10372 KB Output is correct
11 Correct 383 ms 10192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6756 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 6 ms 6736 KB Output is correct
10 Correct 5 ms 6736 KB Output is correct
11 Correct 5 ms 6736 KB Output is correct
12 Correct 6 ms 6736 KB Output is correct
13 Correct 5 ms 6776 KB Output is correct
14 Correct 5 ms 6736 KB Output is correct
15 Correct 5 ms 6736 KB Output is correct
16 Correct 5 ms 6736 KB Output is correct
17 Correct 5 ms 6780 KB Output is correct
18 Correct 244 ms 8892 KB Output is correct
19 Correct 331 ms 9856 KB Output is correct
20 Correct 190 ms 8648 KB Output is correct
21 Correct 368 ms 9980 KB Output is correct
22 Correct 353 ms 10068 KB Output is correct
23 Correct 379 ms 10192 KB Output is correct
24 Correct 381 ms 10164 KB Output is correct
25 Correct 408 ms 10372 KB Output is correct
26 Correct 392 ms 10164 KB Output is correct
27 Correct 400 ms 10372 KB Output is correct
28 Correct 383 ms 10192 KB Output is correct
29 Correct 383 ms 11956 KB Output is correct
30 Correct 102 ms 7504 KB Output is correct
31 Correct 229 ms 8144 KB Output is correct
32 Correct 595 ms 10188 KB Output is correct
33 Correct 233 ms 8284 KB Output is correct
34 Correct 260 ms 8400 KB Output is correct
35 Correct 157 ms 7672 KB Output is correct
36 Correct 87 ms 7416 KB Output is correct
37 Correct 109 ms 7516 KB Output is correct
38 Correct 369 ms 10376 KB Output is correct
39 Correct 396 ms 10380 KB Output is correct
40 Correct 385 ms 10164 KB Output is correct
41 Correct 416 ms 10368 KB Output is correct
42 Correct 409 ms 10164 KB Output is correct
43 Correct 409 ms 11956 KB Output is correct
44 Correct 425 ms 11984 KB Output is correct
45 Correct 383 ms 11956 KB Output is correct
46 Correct 398 ms 11968 KB Output is correct
47 Correct 428 ms 11956 KB Output is correct
48 Correct 464 ms 10680 KB Output is correct
49 Correct 445 ms 10680 KB Output is correct
50 Correct 451 ms 10420 KB Output is correct
51 Correct 446 ms 10420 KB Output is correct
52 Correct 477 ms 10712 KB Output is correct
53 Correct 483 ms 10712 KB Output is correct
54 Correct 449 ms 10676 KB Output is correct