# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
967731 |
2024-04-22T17:20:15 Z |
jadai007 |
Vudu (COCI15_vudu) |
C++14 |
|
253 ms |
62980 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 = 1; 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 |
4 ms |
10588 KB |
Output is correct |
2 |
Correct |
4 ms |
10588 KB |
Output is correct |
3 |
Correct |
3 ms |
10584 KB |
Output is correct |
4 |
Correct |
253 ms |
32200 KB |
Output is correct |
5 |
Correct |
143 ms |
27848 KB |
Output is correct |
6 |
Runtime error |
143 ms |
62980 KB |
Execution killed with signal 11 |
7 |
Correct |
217 ms |
32048 KB |
Output is correct |
8 |
Correct |
196 ms |
31536 KB |
Output is correct |
9 |
Correct |
250 ms |
33076 KB |
Output is correct |
10 |
Correct |
215 ms |
31544 KB |
Output is correct |