Submission #237326

# Submission time Handle Problem Language Result Execution time Memory
237326 2020-06-06T01:51:01 Z mohamedsobhi777 Vudu (COCI15_vudu) C++14
112 / 140
1000 ms 62064 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;

int n, k;
int a[N];


vector<long long> srtd ; 
unordered_map<long long, int > mp ;
int bit[N] ;

void add(int x){
        for(;x < N ;x += x&-x ){
                bit[x] ++ ; 
        }
}

int get(int x){
        if(x < 0 ) return 0; 
        int ret =0 ; 
        for(;x;x-=x&-x){
                ret+=bit[x] ;
        }
        return ret ; 
}

int t =1 ; 

int com(long long x){
        int ret = mp[x] ; 
        if(ret)return ret ; 
        mp[x] = t++ ; 
        return t-1 ; 
}

void init(){
        srtd.push_back(0) ; 
        sort(srtd.begin() , srtd.end()) ; 
        for(int i = 0 ; i < (int) srtd.size() ;i++){
                com(srtd[i]) ;
        }
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);

        cin >> n;
        for (int i = 0; i < n; i++)
        {
                cin >> a[i];
        }

        cin >> k;
        
        long long sum = 0 ;

        for (int i = 0; i < n; i++)
        {
                a[i] -= k;
                sum+= a[i] ; 
                srtd.push_back(sum) ;
        }

        init() ;
        
        long long ans = 0;
        long long pre = 0;
        add(com(0)) ; 
        for (int i = 0; i < n; i++)
        {
                pre += a[i];
                int aux = com(pre) ; 
                ans+= get(aux)  ;
                add(aux) ; 
        }
        cout << ans;
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 896 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Execution timed out 1097 ms 61396 KB Time limit exceeded
5 Correct 586 ms 33364 KB Output is correct
6 Correct 960 ms 47700 KB Output is correct
7 Correct 992 ms 49492 KB Output is correct
8 Correct 823 ms 43732 KB Output is correct
9 Execution timed out 1091 ms 62064 KB Time limit exceeded
10 Correct 907 ms 48216 KB Output is correct