Submission #893794

# Submission time Handle Problem Language Result Execution time Memory
893794 2023-12-27T12:37:30 Z vjudge1 Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 6236 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 5e3 + 2;
const int M = 7e6 + 1;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;

int mult(int a, int b) {
    return a * 1LL * b % mod;
}

int sum(int a, int b) {
    a %= mod; 
    if (a + b < 0)
        return a + b + mod;
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}

ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % mod;
    } else {
        ll b = binpow(a, n / 2);
        return b * b % mod;
    }
}

struct fenwick{
    vector<int> bt;
    int sz = 0;
    fenwick(int n){
        bt.assign(n + 1, 0);
        sz = n;
    }

    int get(int r){
        int ret = 0;
        for(; r >= 0; r = (r & (r + 1)) - 1)
            ret += bt[r];
        return ret;
    }

    void add(int i, int v){
        for(; i <= sz; i = (i | (i + 1)))
            bt[i] += v;
    }
};

void solve(){
    int n;
    cin >> n;
    set<int> st;
    int a[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> a[i], st.insert(a[i]);
    
    int ans = 0;
    for(auto e : st){
        fenwick f = fenwick(2 * n + 4);
        int cur = 0;
        for(int i = 1; i <= n; i++){
            f.add(cur + n, 1);
            if(a[i] != e)
                cur--;
            else
                cur++;
            ans += f.get(cur - 1 + n);
        }
    }
    cout << ans << '\n';
}   

signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 600 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 600 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 348 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 1 ms 348 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 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3816 KB Output is correct
2 Correct 19 ms 4800 KB Output is correct
3 Correct 10 ms 2980 KB Output is correct
4 Correct 21 ms 5064 KB Output is correct
5 Correct 19 ms 5208 KB Output is correct
6 Correct 22 ms 5468 KB Output is correct
7 Correct 21 ms 5556 KB Output is correct
8 Correct 22 ms 5464 KB Output is correct
9 Correct 22 ms 5468 KB Output is correct
10 Correct 24 ms 5464 KB Output is correct
11 Correct 14 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 600 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 348 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 1 ms 348 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 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 17 ms 3816 KB Output is correct
19 Correct 19 ms 4800 KB Output is correct
20 Correct 10 ms 2980 KB Output is correct
21 Correct 21 ms 5064 KB Output is correct
22 Correct 19 ms 5208 KB Output is correct
23 Correct 22 ms 5468 KB Output is correct
24 Correct 21 ms 5556 KB Output is correct
25 Correct 22 ms 5464 KB Output is correct
26 Correct 22 ms 5468 KB Output is correct
27 Correct 24 ms 5464 KB Output is correct
28 Correct 14 ms 5468 KB Output is correct
29 Correct 21 ms 6236 KB Output is correct
30 Execution timed out 3043 ms 3464 KB Time limit exceeded
31 Halted 0 ms 0 KB -