# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
94478 | theknife2001 | Vudu (COCI15_vudu) | C++11 | 1072 ms | 66560 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define mid (l+r)/2
using namespace std;
map < ll , int > mp;
const int N=1e6+55;
short tree[N*4];
ll sum[N];
ll a[N];
int n;
void update(int node , int l , int r , int ind)
{
if(l==r&&l==ind)
{
tree[node]++;
return ;
}
if(ind<=mid)
update(node*2,l,mid,ind);
else
update(node*2+1,mid+1,r,ind);
tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node , int l , int r , int x , int y)
{
if(x<=l&&r<=y)
return tree[node];
if(l>y||r<x)
return 0;
return query(node*2,l,mid,x,y)+query(node*2+1,mid+1,r,x,y);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int p;
cin>>p;
for(int i=n-1;i>=0;i--)
{
sum[i]=a[i]-p;
if(i!=n-1)
sum[i]+=sum[i+1];
a[i]=sum[i];
}
sort(a,a+n);
int cnt=1;
for(int i=0;i<n;i++)
{
if(mp[a[i]]==0)
mp[a[i]]=cnt++;
}
ll ans=0;
for(int i=n-1;i>=0;i--)
{
if(sum[i]>=0)
ans++;
ans+=query(1,0,1e6,0,mp[sum[i]]);
update(1,0,1e6,mp[sum[i]]);
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |