#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
struct Fen {
vector<ll> tree;
void init(int n){
tree.assign(n + 1 , 0LL);
}
void set(int i , ll val , int n){
i++;
while(i <= n){
tree[i] += val;
i += (i & (-i));
}
}
ll sum(int i){
i++;
ll ans = 0;
while(i > 0){
ans += tree[i];
i -= (i & (-i));
}
return ans;
}
void build(vector<int>& a){
int n = a.size();
for(int i = 0; i < n; i++){
set(i , a[i] , n);
}
}
};
void solve(){
int n;
cin >> n;
ll arr[n];
for(int i = 0; i < n; i++)cin >> arr[i];
ll p;
cin >> p;
for(int i = 0; i < n; i++)arr[i] -= p;
ll pre[n + 1];
pre[n] = 0;
map<int,vector<int>> m;
m[0].pb(n);
for(int i = n - 1; i >= 0; i--){
pre[i] = pre[i + 1] + arr[i];
m[pre[i]].pb(i);
}
int cur = 1;
for(auto it : m){
for(int j : it.vs)pre[j] = cur;
cur++;
}
ll ans = 0;
Fen ft;
ft.init(cur + 5);
for(int i = 0; i < n; i++){
ft.set(pre[i] , 1 , cur + 5);
ll x = pre[i + 1];
ans += (i + 1LL) - ((ll)ft.sum(x - 1));
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1192 KB |
Output is correct |
2 |
Correct |
3 ms |
972 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Runtime error |
450 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Runtime error |
452 ms |
65540 KB |
Execution killed with signal 9 |
6 |
Runtime error |
467 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
470 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
431 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Runtime error |
468 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
440 ms |
65540 KB |
Execution killed with signal 9 |