답안 #967729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967729 2024-04-22T17:16:20 Z jadai007 Vudu (COCI15_vudu) C++14
126 / 140
265 ms 63004 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;

int n,k,arr[1000010], ans, qs[1000010];
vector<int> vc;

struct FenwickTree {
    vector<int> fwt;
    FenwickTree(int sz) {
        fwt.resize(sz + 10000);
    }
    int query(int idx) {
        int ans = 0;
        for (idx++; idx > 0; idx -= idx & -idx) ans += fwt[idx];
        return ans;
    }
    void update(int idx) {
        for (idx++; idx < fwt.size(); idx += idx & -idx) fwt[idx]++;
    }
} fwt(1e6);

signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i<=n; ++i) cin >> arr[i];
    for(int i = 1; i<=n; ++i) qs[i] = qs[i - 1] + arr[i];
    cin >> k;
    for(int i = 0; i<=n; ++i) vc.push_back(qs[i] - k*i);
    sort(vc.begin(), vc.end());
    vc.erase(unique(vc.begin(), vc.end()));
    for(int i = 0; i<=n; ++i){
        int idx = lower_bound(vc.begin(), vc.end(), qs[i] - k*i) - vc.begin();
        ans += fwt.query(idx);
        fwt.update(idx);
    }
    cout << ans;
}

Compilation message

vudu.cpp: In member function 'void FenwickTree::update(long long int)':
vudu.cpp:20:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (idx++; idx < fwt.size(); idx += idx & -idx) fwt[idx]++;
      |                     ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 3 ms 10588 KB Output is correct
4 Correct 265 ms 32312 KB Output is correct
5 Correct 135 ms 27080 KB Output is correct
6 Runtime error 141 ms 63004 KB Execution killed with signal 11
7 Correct 245 ms 31688 KB Output is correct
8 Correct 220 ms 31944 KB Output is correct
9 Correct 251 ms 33988 KB Output is correct
10 Correct 219 ms 32812 KB Output is correct