답안 #731321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731321 2023-04-27T09:59:51 Z bgnbvnbv Vudu (COCI15_vudu) C++14
140 / 140
390 ms 33580 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e6;
const ll inf=1e18;
const ll mod=1e9+7;
vector<ll>vec;
ll bit[maxN];
ll n;
void update(ll p)
{
    p=lower_bound(vec.begin(),vec.end(),p)-vec.begin()+1;
    while(p<=n)
    {
        bit[p]++;
        p+=(p&(-p));
    }
}
ll get(ll p)
{
    ll res=0;
    while(p>0)
    {
        res+=bit[p];
        p-=(p&(-p));
    }
    return res;
}
ll a[maxN],p;
void solve()
{
    cin >> n;
    ll ans=0;
    for(int i=1;i<=n;i++) cin >> a[i];
    cin >> p;
    for(int i=1;i<=n;i++) a[i]-=p,a[i]+=a[i-1],vec.pb(a[i]);
    sort(vec.begin(),vec.end());
    update(0);
    for(int i=1;i<=n;i++)
    {
        ll p=upper_bound(vec.begin(),vec.end(),a[i])-vec.begin();
        ans+=get(p);
        update(a[i]);
    }
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 390 ms 32380 KB Output is correct
5 Correct 214 ms 18544 KB Output is correct
6 Correct 310 ms 28748 KB Output is correct
7 Correct 314 ms 30004 KB Output is correct
8 Correct 277 ms 25944 KB Output is correct
9 Correct 369 ms 33580 KB Output is correct
10 Correct 335 ms 29136 KB Output is correct