# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
98776 |
2019-02-25T20:48:55 Z |
someone_aa |
Vudu (COCI15_vudu) |
C++17 |
|
837 ms |
66560 KB |
#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 = 3 * 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;
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;
vector<ll>values;
ll sum = 0LL;
for(ll i=1LL;i<=n;i++) {
values.pb(sum - d*i);
sum += arr[i];
values.pb(sum - d*i - d);
}
sort(values.begin(), values.end());
int br = 1;
for(ll i:values) {
ind[i] = 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
3 |
Correct |
6 ms |
840 KB |
Output is correct |
4 |
Runtime error |
663 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Correct |
837 ms |
51844 KB |
Output is correct |
6 |
Runtime error |
717 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
636 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
633 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
647 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
697 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |