Submission #907504

# Submission time Handle Problem Language Result Execution time Memory
907504 2024-01-15T18:06:56 Z vjudge1 Izbori (COCI22_izbori) C++17
110 / 110
622 ms 22100 KB
#include<bits/stdc++.h>

using namespace std;

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

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]]--;
        }
    }
    //cout << res << '\n';
    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];
            dp[pfs[j]] = dp[pfs[j] - 1] + sl[pfs[j] - 1];
            sl[pfs[j]]++;
            res += dp[pfs[j]];
        }
        for (int j = 1; j <= n; j++) {
            sl[pfs[j]] = 0;
            dp[pfs[j]] = 0;
        }
    }
    cout << res << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:55: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]
   55 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4580 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4580 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 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4524 KB Output is correct
11 Correct 4 ms 4444 KB Output is correct
12 Correct 5 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4444 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 4 ms 4588 KB Output is correct
17 Correct 4 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 14812 KB Output is correct
2 Correct 262 ms 16856 KB Output is correct
3 Correct 147 ms 12752 KB Output is correct
4 Correct 339 ms 16720 KB Output is correct
5 Correct 278 ms 16852 KB Output is correct
6 Correct 295 ms 16864 KB Output is correct
7 Correct 297 ms 16844 KB Output is correct
8 Correct 295 ms 16720 KB Output is correct
9 Correct 301 ms 17096 KB Output is correct
10 Correct 297 ms 16724 KB Output is correct
11 Correct 278 ms 22100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4580 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 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 4 ms 4444 KB Output is correct
10 Correct 4 ms 4524 KB Output is correct
11 Correct 4 ms 4444 KB Output is correct
12 Correct 5 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4444 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 4 ms 4588 KB Output is correct
17 Correct 4 ms 10588 KB Output is correct
18 Correct 195 ms 14812 KB Output is correct
19 Correct 262 ms 16856 KB Output is correct
20 Correct 147 ms 12752 KB Output is correct
21 Correct 339 ms 16720 KB Output is correct
22 Correct 278 ms 16852 KB Output is correct
23 Correct 295 ms 16864 KB Output is correct
24 Correct 297 ms 16844 KB Output is correct
25 Correct 295 ms 16720 KB Output is correct
26 Correct 301 ms 17096 KB Output is correct
27 Correct 297 ms 16724 KB Output is correct
28 Correct 278 ms 22100 KB Output is correct
29 Correct 339 ms 21976 KB Output is correct
30 Correct 117 ms 4956 KB Output is correct
31 Correct 249 ms 5712 KB Output is correct
32 Correct 622 ms 10584 KB Output is correct
33 Correct 263 ms 7668 KB Output is correct
34 Correct 269 ms 7760 KB Output is correct
35 Correct 185 ms 5332 KB Output is correct
36 Correct 100 ms 4956 KB Output is correct
37 Correct 131 ms 4952 KB Output is correct
38 Correct 287 ms 17624 KB Output is correct
39 Correct 298 ms 17744 KB Output is correct
40 Correct 290 ms 17624 KB Output is correct
41 Correct 287 ms 17632 KB Output is correct
42 Correct 287 ms 17744 KB Output is correct
43 Correct 309 ms 18132 KB Output is correct
44 Correct 321 ms 18136 KB Output is correct
45 Correct 315 ms 18128 KB Output is correct
46 Correct 324 ms 18004 KB Output is correct
47 Correct 314 ms 18168 KB Output is correct
48 Correct 451 ms 18400 KB Output is correct
49 Correct 492 ms 18560 KB Output is correct
50 Correct 391 ms 18388 KB Output is correct
51 Correct 384 ms 18256 KB Output is correct
52 Correct 346 ms 8676 KB Output is correct
53 Correct 594 ms 18256 KB Output is correct
54 Correct 457 ms 18652 KB Output is correct