답안 #220394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220394 2020-04-07T19:55:51 Z XmtosX Vudu (COCI15_vudu) C++17
140 / 140
326 ms 31608 KB
#include <bits/stdc++.h>
using namespace std;
const int N=2e6+6;
int n,a[N],P;
long long pfx[N];
pair<long long,int> p[N];
int BIT[N];
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+1)
    {
        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;
        p[i]={pfx[i],i};
    }
    sort(p,p+n+1);
    pfx[p[0].second]=0;
    int cnt=0;
    for (int i=1;i<=n;i++)
    {
        if (p[i].first!=p[i-1].first)
            cnt++;
        pfx[p[i].second]=cnt;
    }
    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:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
vudu.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
vudu.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&P);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 318 ms 30584 KB Output is correct
5 Correct 181 ms 17400 KB Output is correct
6 Correct 285 ms 27264 KB Output is correct
7 Correct 288 ms 28152 KB Output is correct
8 Correct 253 ms 24560 KB Output is correct
9 Correct 326 ms 31608 KB Output is correct
10 Correct 280 ms 27512 KB Output is correct