Submission #237329

# Submission time Handle Problem Language Result Execution time Memory
237329 2020-06-06T02:00:24 Z mohamedsobhi777 Vudu (COCI15_vudu) C++14
42 / 140
1000 ms 57792 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;

int n, k;
int a[N];


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


int read_int()
{
        char r;
        bool start = false, neg = false;
        int ret = 0;
        while (true)
        {
                r = getchar();
                if ((r - '0' < 0 || r - '0' > 9) && r != '-' && !start)
                {
                        continue;
                }
                if ((r - '0' < 0 || r - '0' > 9) && r != '-' && start)
                {
                        break;
                }
                if (start)
                        ret *= 10;
                start = true;
                if (r == '-')
                        neg = true;
                else
                        ret += r - '0';
        }
        if (!neg)
                return ret;
        else
                return -ret;
}

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()
{
  
        //freopen("in.in", "r", stdin);

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

        k = read_int(); 
        
        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 9 ms 768 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Execution timed out 1096 ms 57768 KB Time limit exceeded
5 Incorrect 621 ms 31040 KB Output isn't correct
6 Incorrect 967 ms 44224 KB Output isn't correct
7 Execution timed out 1018 ms 45888 KB Time limit exceeded
8 Incorrect 862 ms 40768 KB Output isn't correct
9 Execution timed out 1098 ms 57792 KB Time limit exceeded
10 Execution timed out 1014 ms 44952 KB Time limit exceeded