답안 #764858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764858 2023-06-24T05:55:58 Z drdilyor Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 5324 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;

struct Fenwick {
    int n;
    vector<int> tree;
    Fenwick() = default;
    Fenwick(int n) : n(n), tree(n) {}
    int sum(int r) {
        int s = 0;
        for (; r >= 0; r = (r&(r+1))-1) s+= tree[r];
        return s;
    }
    void inc(int i, int d=1) {
        for (; i < n; i |= i+1) tree[i] += d;
    }
};


int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int& i : arr) cin >> i;
    set<int> poss(arr.begin(), arr.end());

    ll cnt = 0;
    for (int x : poss) {
        vector<int> brr(n+1);
        brr[0] = n;
        for (int i = 0; i < n; i++){ 
            brr[i+1] = brr[i] + (arr[i] == x ? 1 : -1);
        }
        Fenwick t(n*2+1);
        t.inc(brr[0]);
        for (int i = 1; i <= n; i++) {
            cnt += t.sum(brr[i]-1);
            t.inc(brr[i]);
        }
    }
    cout << cnt << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 9 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2656 KB Output is correct
2 Correct 23 ms 3284 KB Output is correct
3 Correct 10 ms 2096 KB Output is correct
4 Correct 17 ms 3452 KB Output is correct
5 Correct 18 ms 3628 KB Output is correct
6 Correct 21 ms 3816 KB Output is correct
7 Correct 20 ms 3812 KB Output is correct
8 Correct 20 ms 3796 KB Output is correct
9 Correct 19 ms 3796 KB Output is correct
10 Correct 25 ms 3956 KB Output is correct
11 Correct 17 ms 3808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 9 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 14 ms 2656 KB Output is correct
19 Correct 23 ms 3284 KB Output is correct
20 Correct 10 ms 2096 KB Output is correct
21 Correct 17 ms 3452 KB Output is correct
22 Correct 18 ms 3628 KB Output is correct
23 Correct 21 ms 3816 KB Output is correct
24 Correct 20 ms 3812 KB Output is correct
25 Correct 20 ms 3796 KB Output is correct
26 Correct 19 ms 3796 KB Output is correct
27 Correct 25 ms 3956 KB Output is correct
28 Correct 17 ms 3808 KB Output is correct
29 Correct 23 ms 5324 KB Output is correct
30 Execution timed out 3058 ms 2768 KB Time limit exceeded
31 Halted 0 ms 0 KB -