# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542477 |
2022-03-26T18:51:09 Z |
Olympia |
Vudu (COCI15_vudu) |
C++17 |
|
350 ms |
65536 KB |
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <limits.h>
using namespace std;
template<class T>
class SegmentTree {
public:
SegmentTree (int N) {
N = (1 << ((int)floor(log2(N - 1)) + 1));
this->N = N;
val.assign(2 * N, ID);
}
void update (int x, T y) {
x += N - 1;
val[x] += y;
while (x != 0) {
x = (x - 1)/2;
val[x] = merge(val[2 * x + 1], val[2 * x + 2]);
}
}
T query (int ind, const int l, const int r, int tl, int tr) {
if (tl >= l && tr <= r) {
return val[ind];
}
if (tr < l || tl > r) {
return ID;
}
return merge(query(2 * ind + 1, l, r, tl, (tl + tr)/2), query(2 * ind + 2, l, r, (tl + tr)/2 + 1, tr));
}
T query (int l, int r) {
return query(0, l, r, 0, N - 1);
}
private:
vector<T> val;
T ID = 0;
T merge (T x, T y) {
return x + y;
}
int N;
};
int main() {
//freopen("balancing.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N; cin >> N;
vector<int64_t> pref = {0};
for (int i = 0; i < N; i++) {
int64_t x; cin >> x; pref.push_back(pref.back() + x);
}
set<int64_t> s;
int64_t P; cin >> P;
for (int i = 0; i <= N; i++) {
s.insert(pref[i] - P * i);
}
SegmentTree<int> st(N + 10);
map<int64_t,int> myMap; int cntr = 0;
for (int64_t i: s) {
myMap[i] = cntr++;
}
int64_t c = 0;
for (int r = 0; r < N; r++) {
st.update(myMap[pref[r] - P * r], 1);
c += (int64_t)st.query(0, myMap[pref[r + 1] - P * (r + 1)]);
}
cout << c;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Runtime error |
350 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
266 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
308 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
291 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
290 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
316 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
319 ms |
65536 KB |
Execution killed with signal 9 |