답안 #270006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270006 2020-08-17T11:53:21 Z mayhoubsaleh Vudu (COCI15_vudu) C++14
56 / 140
731 ms 65540 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const ll maxn=2e6;
const ll inf=1e9+10;
const ll mod=1e9+7;
const ll base=27;

ll n,avg;
ll pre[maxn];
set<ll>s;
ll cnt;
unordered_map<ll,ll>h;
ll bit[maxn];

void add(ll id){
    for(;id<=cnt;id+=id&(-id)){
        bit[id]++;
    }
}

ll qur(ll id){
    ll ret=0;
    for(;id;id-=id&(-id)){
        ret+=bit[id];
    }
    return ret;
}
int main()
{
    IOS
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>pre[i];
    }
    cin>>avg;
    s.insert(0);
    for(ll i=1;i<=n;i++){
        pre[i]=pre[i]-avg+pre[i-1];
        s.insert(pre[i]);
    }

    for(auto it:s){
        h[it]=++cnt;
    }
    //cout<<cnt<<endl;
    add(h[0]);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=qur(h[pre[i]]);
        add(h[pre[i]]);
    }

    cout<<ans<<endl;
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1024 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 3 ms 896 KB Output is correct
4 Runtime error 551 ms 65540 KB Execution killed with signal 9
5 Correct 731 ms 60152 KB Output is correct
6 Runtime error 539 ms 65536 KB Execution killed with signal 9
7 Runtime error 505 ms 65540 KB Execution killed with signal 9
8 Runtime error 551 ms 65540 KB Execution killed with signal 9
9 Runtime error 477 ms 65540 KB Execution killed with signal 9
10 Runtime error 554 ms 65540 KB Execution killed with signal 9