#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define P pair<ll, ll>
using namespace std;
const int maxn = 1000100;
const int maxm = 2 * maxn;
int tree[maxm], m;
void update(int x,int val) {
while(x<=m) {
tree[x]+=val; x+=(x&-x);
}
}
int query(int x) {
int res=0;
while(x>0) {
res+=tree[x]; x-=(x&-x);
}
return res;
}
ll n, d, arr[maxn];
map<ll, int> ind;
set<ll>values;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) {
cin>>arr[i];
}
cin>>d;
ll sum = 0LL;
for(ll i=1LL;i<=n;i++) {
ind[sum-d*i] = 1;
sum += arr[i];
ind[sum-d*i - d] = 1;
}
int br = 1;
for(auto i:ind) {
i.second = br++;
}
m = br;
sum = 0LL;
ll result = 0LL;
for(int i=1;i<=n;i++) {
update(ind[sum - d*i], 1);
//cout<<i<<": "<<sum-d*i<<", "<<ind[sum-d*i]<<" -> ";
sum += arr[i];
result += 1LL * query(ind[sum - d*i - d]);
//cout<<sum - d*i - d<<", "<<ind[sum-d*i-d]<<"\n";
}
cout<<result<<"\n";
return 0;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:46:14: warning: variable 'i' set but not used [-Wunused-but-set-variable]
for(auto i:ind) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
896 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
4 |
Runtime error |
938 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Incorrect |
817 ms |
38864 KB |
Output isn't correct |
6 |
Execution timed out |
1056 ms |
64784 KB |
Time limit exceeded |
7 |
Execution timed out |
1092 ms |
66560 KB |
Time limit exceeded |
8 |
Execution timed out |
1057 ms |
54816 KB |
Time limit exceeded |
9 |
Runtime error |
784 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Execution timed out |
1078 ms |
66040 KB |
Time limit exceeded |