답안 #907483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907483 2024-01-15T17:32:08 Z vjudge1 Izbori (COCI22_izbori) C++17
110 / 110
549 ms 16724 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
int n, a[200001], num = 0, cnt[200001], sz = 319, cnt2[200001], res = 0, c[200001], pfs[200001], dp[200001], sl[400001];
pair<int, int> b[200001];
vector<int> v;
bool check[200001];

bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i].first = a[i];
        b[i].second = i;
    }
    int last = -1;
    sort(b + 1, b + 1 + n);
    for (int i = 1; i <= n; i++) {
        int l2 = b[i].first;
        if(b[i].first == last) b[i].first = num;
        else b[i].first = ++num;
        last = l2;
    }
    sort(b + 1, b + 1 + n, cmp);
    for (int i = 1; i <= n; i++) {
        a[i] = b[i].first;
        cnt[a[i]]++;
        if(cnt[a[i]] > sz && !check[a[i]]) {
            v.push_back(a[i]);
            check[a[i]] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        int mx = 1;
        for (int j = i; j <= min(i + 2 * sz - 1, n); j++) {
            num = j - i + 1;
            if(cnt[a[j]] <= sz) {
                cnt2[a[j]]++;
                mx = max(mx, cnt2[a[j]]);
                if(mx > num / 2) res++;
            }
        }
        for (int j = i; j <= min(i + 2 * sz - 1, n); j++) {
            if(cnt[a[j]] < sz) cnt2[a[j]]--;
        }
    }
    for (int i = 0; i < v.size(); i++) {
        int bnum = v[i];
        pfs[0] = n;
        sl[n] = 1;
        for (int j = 1; j <= n; j++) {
            if(a[j] == bnum) c[j] = 1;
            else c[j] = -1;
            pfs[j] = pfs[j - 1] + c[j];
            if(pfs[j] > pfs[j - 1]) {
                dp[j] = dp[j - 1] + sl[pfs[j - 1]];
            }
            else {
                dp[j] = dp[j - 1] - sl[pfs[j]];
            }
            sl[pfs[j]]++;
            res += dp[j];
        }
        for (int j = 1; j <= n; j++) {
            sl[pfs[j]] = 0;
            dp[j] = 0;
            pfs[j] = 0;
        }
    }
    cout << res << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:54:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 3 ms 4576 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 3 ms 4444 KB Output is correct
12 Correct 3 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4512 KB Output is correct
15 Correct 3 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 4 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 13528 KB Output is correct
2 Correct 222 ms 14712 KB Output is correct
3 Correct 123 ms 11440 KB Output is correct
4 Correct 225 ms 14676 KB Output is correct
5 Correct 241 ms 14932 KB Output is correct
6 Correct 249 ms 14960 KB Output is correct
7 Correct 246 ms 14932 KB Output is correct
8 Correct 250 ms 14960 KB Output is correct
9 Correct 248 ms 14964 KB Output is correct
10 Correct 252 ms 14964 KB Output is correct
11 Correct 225 ms 14960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 3 ms 4576 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 3 ms 4444 KB Output is correct
12 Correct 3 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4512 KB Output is correct
15 Correct 3 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 4 ms 10588 KB Output is correct
18 Correct 162 ms 13528 KB Output is correct
19 Correct 222 ms 14712 KB Output is correct
20 Correct 123 ms 11440 KB Output is correct
21 Correct 225 ms 14676 KB Output is correct
22 Correct 241 ms 14932 KB Output is correct
23 Correct 249 ms 14960 KB Output is correct
24 Correct 246 ms 14932 KB Output is correct
25 Correct 250 ms 14960 KB Output is correct
26 Correct 248 ms 14964 KB Output is correct
27 Correct 252 ms 14964 KB Output is correct
28 Correct 225 ms 14960 KB Output is correct
29 Correct 231 ms 16724 KB Output is correct
30 Correct 75 ms 5112 KB Output is correct
31 Correct 157 ms 5648 KB Output is correct
32 Correct 399 ms 9984 KB Output is correct
33 Correct 175 ms 5980 KB Output is correct
34 Correct 175 ms 6056 KB Output is correct
35 Correct 112 ms 5472 KB Output is correct
36 Correct 66 ms 4956 KB Output is correct
37 Correct 81 ms 5160 KB Output is correct
38 Correct 244 ms 14952 KB Output is correct
39 Correct 242 ms 14932 KB Output is correct
40 Correct 252 ms 14932 KB Output is correct
41 Correct 241 ms 15080 KB Output is correct
42 Correct 249 ms 15188 KB Output is correct
43 Correct 257 ms 16544 KB Output is correct
44 Correct 255 ms 16540 KB Output is correct
45 Correct 254 ms 16556 KB Output is correct
46 Correct 255 ms 16724 KB Output is correct
47 Correct 262 ms 16724 KB Output is correct
48 Correct 400 ms 15484 KB Output is correct
49 Correct 412 ms 15264 KB Output is correct
50 Correct 308 ms 15188 KB Output is correct
51 Correct 306 ms 15188 KB Output is correct
52 Correct 549 ms 15528 KB Output is correct
53 Correct 517 ms 15444 KB Output is correct
54 Correct 401 ms 15252 KB Output is correct