Submission #220368

# Submission time Handle Problem Language Result Execution time Memory
220368 2020-04-07T18:38:16 Z XmtosX Vudu (COCI15_vudu) C++17
98 / 140
945 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+6;
int n,a[N],p;
long long pfx[N];
set<long long> s;
int BIT[N];
unordered_map <long long,int> r;
int query(int x)
{
    int sum = 0;
    x++;
    while (x>0)
    {
        sum += BIT[x];
        x -= x & (-x);
    }
    return sum;
}
void update(int x)
{
    x++;
    while (x <= n)
    {
        BIT[x] ++;
        x += x & (-x);
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&p);
    for (int i=1;i<=n;i++)
    {
        pfx[i]=pfx[i-1]+a[i]-p;
        s.insert(pfx[i]);
    }
    s.insert(0);
    int cnt=0;
    while (!s.empty())
    {
        r[*s.begin()]=cnt++;
        s.erase(s.begin());
    }
    for (int i=0;i<=n;i++)
    {
        pfx[i]=r[pfx[i]];
    }
    long long ans=0;
    for (int i=0;i<=n;i++)
    {
        ans+= query(pfx[i]);
        update(pfx[i]);
    }
    cout <<ans;
    return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
vudu.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
vudu.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&p);
     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1024 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
4 Runtime error 666 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Correct 571 ms 48776 KB Output is correct
6 Incorrect 945 ms 65536 KB Output isn't correct
7 Correct 923 ms 65536 KB Output is correct
8 Correct 835 ms 64032 KB Output is correct
9 Runtime error 607 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Correct 912 ms 65536 KB Output is correct