#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;
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);
}
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 |
7 ms |
4948 KB |
Output is correct |
2 |
Correct |
7 ms |
4820 KB |
Output is correct |
3 |
Correct |
5 ms |
4820 KB |
Output is correct |
4 |
Runtime error |
381 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
283 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
318 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
307 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
303 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
341 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
301 ms |
65536 KB |
Execution killed with signal 9 |