Submission #971349

# Submission time Handle Problem Language Result Execution time Memory
971349 2024-04-28T11:45:12 Z RandomUser Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 5576 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

struct BIT {
    int n;
    vector<int> tree;

    void config(int _n) {
        n = _n + 10;
        tree.resize(_n+60);
    }

    void update(int p, int v) {
        for(p++; p<n; p+=p&-p) tree[p] += v;
    }

    int query(int p) {
        int ans = 0;
        for(p++; p>0; p-=p&-p) ans += tree[p];
        return ans;
    }

    int query(int l, int r) { return query(r) - query(l-1); }
    void reset() { for(int &x : tree) x = 0; }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n;
    ll ans = 0;
    cin >> n;

    vector<int> v(n+1);
    set<int> s;
    for(int i=1; i<=n; i++) cin >> v[i], s.insert(v[i]);

    vector<int> comp(all(s));

    BIT bit; bit.config(3*n+5);
    for(int &x : comp) {
        int sum = 0;
        bit.update(n+1, 1);
        for(int i=1; i<=n; i++) {
            sum += (v[i] == x);
            ans += bit.query(2*sum - i - 1 + (n + 1));
            bit.update(2*sum - i + (n + 1), 1);
        }
        bit.reset();
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2804 KB Output is correct
2 Correct 18 ms 3420 KB Output is correct
3 Correct 10 ms 2136 KB Output is correct
4 Correct 18 ms 3416 KB Output is correct
5 Correct 19 ms 3672 KB Output is correct
6 Correct 21 ms 3932 KB Output is correct
7 Correct 21 ms 3928 KB Output is correct
8 Correct 22 ms 3928 KB Output is correct
9 Correct 21 ms 3932 KB Output is correct
10 Correct 20 ms 3932 KB Output is correct
11 Correct 14 ms 4000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 14 ms 2804 KB Output is correct
19 Correct 18 ms 3420 KB Output is correct
20 Correct 10 ms 2136 KB Output is correct
21 Correct 18 ms 3416 KB Output is correct
22 Correct 19 ms 3672 KB Output is correct
23 Correct 21 ms 3932 KB Output is correct
24 Correct 21 ms 3928 KB Output is correct
25 Correct 22 ms 3928 KB Output is correct
26 Correct 21 ms 3932 KB Output is correct
27 Correct 20 ms 3932 KB Output is correct
28 Correct 14 ms 4000 KB Output is correct
29 Correct 22 ms 5576 KB Output is correct
30 Execution timed out 3041 ms 2908 KB Time limit exceeded
31 Halted 0 ms 0 KB -