Submission #950198

# Submission time Handle Problem Language Result Execution time Memory
950198 2024-03-20T06:48:23 Z vjudge1 Vudu (COCI15_vudu) C++17
140 / 140
267 ms 23988 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define int long long
const int N = 1e6;

struct Fenwick{
    int n;
    vector<int> fenw;
    Fenwick(int sz){
        n = sz;
        fenw.resize(n+1, 0);
    };
    
    void add(int i, int x){
        for(; i <= n; i+= i & -i){
            fenw[i]+= x;
        }
    }
    
    int pref(int i){
        int s =0;
        for(; i >= 1; i-= i & -i){
            s+= fenw[i];
        }
        return s;
    }
    
    int get(int l, int r){
        return pref(r) - pref(l-1);
    }
    
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for(auto &e : a) cin >> e;
    int p; cin >> p;
    for(auto &e : a) e-= p;
    int sum = 0;
    vector<int> x;
    x.push_back(sum);
    for(int i = 0;i < n; i++){
        sum+= a[i];
        x.push_back(sum);
    }
    
    sort(all(x));
    x.erase(unique(all(x)), x.end());
    Fenwick fenw(N);
    
    auto idx = [&](int el){
        return lower_bound(all(x), el) - x.begin() + 1;
   };
    
    fenw.add(idx(0), 1);
    sum = 0;
    int ans = 0;
    for(int i = 0;i < n; i++){
        sum+= a[i];
        int id = idx(sum);
        ans+= fenw.pref(id);
        fenw.add(id, 1);
    }
    
    cout << ans;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 258 ms 23984 KB Output is correct
5 Correct 142 ms 17880 KB Output is correct
6 Correct 212 ms 22712 KB Output is correct
7 Correct 217 ms 22352 KB Output is correct
8 Correct 197 ms 21952 KB Output is correct
9 Correct 267 ms 23988 KB Output is correct
10 Correct 214 ms 23216 KB Output is correct