# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
220368 | XmtosX | Vudu (COCI15_vudu) | C++17 | 945 ms | 65540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |