답안 #201798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201798 2020-02-12T02:52:40 Z mdn2002 Vudu (COCI15_vudu) C++14
0 / 140
931 ms 48320 KB
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long n,p,sum[1000006],tree[4000006],inda[1000006];
vector<pair<long long,int> >pr;
void up(int nod,int l,int r,int x)
{
    if(x<l||r<x)return;
    if(l==r)
    {
        tree[nod]++;
        return;
    }
    int mid=(l+r)/2;
    up(nod*2,l,mid,x);
    up(nod*2+1,mid+1,r,x);
    tree[nod]=tree[nod*2]+tree[nod*2+1];
}
long long qr(int nod,int l,int r,int x,int y)
{
    if(x<=l&&r<=y)return tree[nod];
    if(r<x||y<l)return 0;
    int mid=(l+r)/2;
    return qr(nod*2,l,mid,x,y)+qr(nod*2+1,mid+1,r,x,y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("empty.in","r",stdin);
    //freopen("empty.out","w",stdout);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        long long x;
        cin>>x;
        sum[i]=sum[i-1]+x;
    }
    cin>>p;
    for(int i=0;i<n;i++)
    {
        long long x=-sum[i-1]+(p*i);
        pr.push_back({x,i});
    }
    sort(pr.begin(),pr.end());
    for(int i=0;i<pr.size();i++)inda[pr[i].second]=i;
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        long long x=inda[i];
        long long y=p-sum[i]+(p*i);
        pair<int,int>z=*lower_bound(pr.begin(),pr.end(),make_pair(y,0));
        if(lower_bound(pr.begin(),pr.end(),make_pair(y,0))==pr.end())continue;
        up(1,0,n+5,x);
        y=z.second;
        ans+=qr(1,0,n+5,y,n+5);
    }
    cout<<ans;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<pr.size();i++)inda[pr[i].second]=i;
                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 888 KB Output isn't correct
2 Incorrect 8 ms 760 KB Output isn't correct
3 Incorrect 8 ms 760 KB Output isn't correct
4 Incorrect 931 ms 47168 KB Output isn't correct
5 Incorrect 480 ms 33984 KB Output isn't correct
6 Incorrect 789 ms 43776 KB Output isn't correct
7 Incorrect 797 ms 44868 KB Output isn't correct
8 Incorrect 685 ms 41024 KB Output isn't correct
9 Incorrect 894 ms 48320 KB Output isn't correct
10 Incorrect 777 ms 44224 KB Output isn't correct