답안 #968020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968020 2024-04-23T06:57:12 Z vjudge1 Vudu (COCI15_vudu) C++17
42 / 140
196 ms 27744 KB
#include<bits/stdc++.h>
 
using namespace std;
 
int n, arr[1000100] , fw[2200100];
long long qs[1000100], k;
vector<int> v;
long long ans;
 
void update(int idx, int val){
    for(; idx <= n; idx+=(idx&-idx)) fw[idx]+=val;
}
 
long long query(int idx){
    long long sum = 0;
    for(; idx; idx-=(idx&-idx)) sum+=fw[idx];
    return sum;
}
 
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i<=n; ++i) cin >> arr[i];
    cin >> k;
    for(int i = 1; i<=n; ++i) qs[i] = qs[i - 1] + arr[i];
    for(int i = 0; i<=n; ++i) v.push_back(qs[i] - i*k);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()));
    //update(1, 1);
    for(int i = 0; i<=n; ++i){
        int id = lower_bound(v.begin(), v.end(), qs[i] - i*k) - v.begin();
        ans+=query(id+1);
        update(id+1, 1);
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Incorrect 191 ms 27212 KB Output isn't correct
5 Incorrect 107 ms 16656 KB Output isn't correct
6 Incorrect 171 ms 26016 KB Output isn't correct
7 Incorrect 166 ms 26928 KB Output isn't correct
8 Incorrect 148 ms 20588 KB Output isn't correct
9 Incorrect 196 ms 27744 KB Output isn't correct
10 Incorrect 162 ms 26100 KB Output isn't correct