Submission #967730

# Submission time Handle Problem Language Result Execution time Memory
967730 2024-04-22T17:19:09 Z jadai007 Vudu (COCI15_vudu) C++14
126 / 140
257 ms 63160 KB
#include<bits/stdc++.h>
#define int long long
 
using namespace std;
 
int n,k,arr[1010000], ans, qs[1010000];
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]++;
      |                     ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10588 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 3 ms 10328 KB Output is correct
4 Correct 257 ms 34108 KB Output is correct
5 Correct 141 ms 27848 KB Output is correct
6 Runtime error 140 ms 63160 KB Execution killed with signal 11
7 Correct 215 ms 31688 KB Output is correct
8 Correct 191 ms 32296 KB Output is correct
9 Correct 251 ms 33960 KB Output is correct
10 Correct 213 ms 32820 KB Output is correct