#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;
struct BIT{
int bit[(int)1e6 + 5];
int pref(long long ind){
int ans = 0;
ind++;
while(ind > 0){
//cout << ind << " ";
ans += bit[ind];
ind -= (ind & (-ind));
}
return ans;
}
int sum(long long l, long long r){
if(l == 0){
return pref(r);
}
return pref(r) - pref(l - 1);
}
void update(int ind, int val){
ind++;
while(ind < (int)1e6 + 5){
bit[ind] += val;
ind += ind & (-ind);
}
}
};
int main() {
//freopen("balancing.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N; cin >> N;
int64_t pref[N + 1];
pref[0] = 0;
for (int i = 0; i < N; i++) {
int64_t x; cin >> x;
pref[i + 1] = pref[i] + x;
}
set<int64_t> s;
int64_t P; cin >> P;
for (int i = 0; i <= N; i++) {
s.insert(pref[i] - P * i);
}
BIT b;
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++) {
b.update(myMap[pref[r] - P * r], 1);
c += (int64_t)b.sum(0, myMap[pref[r + 1] - P * (r + 1)]);
}
cout << c;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4968 KB |
Output is correct |
2 |
Correct |
5 ms |
4820 KB |
Output is correct |
3 |
Correct |
5 ms |
4692 KB |
Output is correct |
4 |
Runtime error |
408 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
327 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
363 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
353 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
344 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
343 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
348 ms |
65536 KB |
Execution killed with signal 9 |