Submission #967729

#TimeUsernameProblemLanguageResultExecution timeMemory
967729jadai007Vudu (COCI15_vudu)C++14
126 / 140
265 ms63004 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...