Submission #335630

# Submission time Handle Problem Language Result Execution time Memory
335630 2020-12-13T11:27:56 Z Joshc Vudu (COCI15_vudu) C++11
112 / 140
1000 ms 65536 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

long long int l[1000001];
int bit[1000001];

int main() {
    long long int n, p, count=1, ans=0;
    scanf("%lld", &n);
    for (int i=1; i<=n; i++) scanf("%lld", &l[i]);
    scanf("%lld", &p);
    l[0] = 0;
    for (int i=1; i<=n; i++) l[i] = l[i-1]+l[i]-p;
    vector<long long int> arr;
    arr.reserve(n+1);
    for (int i=0; i<=n; i++) arr.push_back(l[i]);
    unordered_map<long long int, long long int> m;
    sort(arr.begin(), arr.end());
    m[arr[0]] = 1;
    for (int i=1; i<=n; i++) {
        if (arr[i] != arr[i-1]) m[arr[i]] = ++count;
    }
    for (int i=n; i>=0; i--) {
        for (long long int j=m[l[i]]; j<=n; j+=j&-j) bit[j]++;
        for (long long int j=m[l[i]]-1; j>0; j-=j&-j) ans += bit[j];
    }
    printf("%lld\n", n*(n+1)/2-ans);
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
vudu.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     for (int i=1; i<=n; i++) scanf("%lld", &l[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~
vudu.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%lld", &p);
      |     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Execution timed out 1087 ms 65536 KB Time limit exceeded
5 Correct 584 ms 42844 KB Output is correct
6 Correct 963 ms 60528 KB Output is correct
7 Correct 968 ms 62456 KB Output is correct
8 Correct 848 ms 55408 KB Output is correct
9 Execution timed out 1055 ms 65536 KB Time limit exceeded
10 Correct 940 ms 61168 KB Output is correct