답안 #100851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100851 2019-03-14T21:15:43 Z dalgerok Vudu (COCI15_vudu) C++17
140 / 140
421 ms 29736 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e6 + 5;



int n, p, t[N];
long long a[N], b[N];

inline int get(int pos){
    int cur = 0;
    for(int i = pos; i >= 0; i &= i + 1, i--){
        cur += t[i];
    }
    return cur;
}
inline int upd(int pos){
    for(int i = pos; i <= n; i |= i + 1){
        t[i] += 1;
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    cin >> p;
    a[0] = -p;
    b[0] = -p;
    for(int i = 1; i <= n; i++){
        a[i] -= p;
        a[i] += a[i - 1];
        b[i] = a[i];
    }
    sort(b, b + n + 1);
    long long ans = 0;
    upd(lower_bound(b, b + n + 1, -p) - b);
    for(int i = 1; i <= n; i++){
        a[i] = lower_bound(b, b + n + 1, a[i]) - b;
        ans += get(a[i]);
        upd(a[i]);
    }
    cout << ans;
}

Compilation message

vudu.cpp: In function 'int upd(int)':
vudu.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 348 ms 28664 KB Output is correct
5 Correct 202 ms 16428 KB Output is correct
6 Correct 299 ms 25464 KB Output is correct
7 Correct 311 ms 26360 KB Output is correct
8 Correct 296 ms 22904 KB Output is correct
9 Correct 421 ms 29736 KB Output is correct
10 Correct 290 ms 25720 KB Output is correct