Submission #444182

# Submission time Handle Problem Language Result Execution time Memory
444182 2021-07-13T09:44:14 Z blue Vudu (COCI15_vudu) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;

long long* a;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin >> N;

    a = new long long[N+1];
    a[0] = 0;
    for(int i = 1; i <= N; i++) cin >> a[i];

    long long P;
    cin >> P;
    for(int i = 1; i <= N; i++)
    {
        a[i] = a[i-1] + (a[i] - P);
    }

    //Count number of (i, j) such that i < j and a[i] < a[j]

    int I[N+1];
    for(int i = 0; i <= N; i++) I[i] = i;
    sort(I, I+N+1, [] (int x, int y)
    {
        if(a[x] == a[y]) return x < y;
        else return a[x] < a[y];
    });

    vector<long long> BIT(2+N, 0);
    long long res = 0;
    for(int i:I)
    {
        for(int j = (i+1)-1; j >= 0+1; j -= j&-j)
            res += BIT[j];

        for(int j = (i+1); j <= N+1; j += j&-j)
            BIT[j] += 1;
    }

    cout << res << '\n';
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:30:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   30 |     sort(I, I+N+1, [] (int x, int y)
      |     ^~~~
      |     qsort