# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
48440 | aleksami | Vudu (COCI15_vudu) | C++14 | 426 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 1000005
ll a[MAXN];
int bit[MAXN];
void update(int idx,int val)
{
while(idx < MAXN)
{
bit[idx]+=val;
idx+=idx&(-idx);
}
}
int get(int idx)
{
int s=0;
while(idx > 0)
{
s+=bit[idx];
idx-=idx&(-idx);
}
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector <ll> v;
ll p;
cin >> p;
for(int i = 1; i <= n; i++)a[i]-=p;
for(int i = 1; i <= n; i++)
{
a[i]+=a[i-1];
v.push_back(a[i]);
}
v.push_back(0LL);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
ll ans = 0LL;
for(int i = 0; i <= n; i++)
{
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
if(i>0)update(a[i-1],1);
ans += get(a[i]);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |