# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
946672 |
2024-03-14T21:48:45 Z |
NourWael |
Vudu (COCI15_vudu) |
C++17 |
|
417 ms |
46768 KB |
#include <bits/extc++.h>
using namespace std;
int const mxN = 1e6+1;
long long a[mxN + 1];
int seg[4*mxN];
int val[mxN+1];
int get ( int node, int l, int r, int ind) {
if(ind<l) return 0;
if(r-1<=ind) return seg[node];
int m = (l+r) / 2;
return get(node*2+1, l, m, ind) + get(node*2+2, m, r, ind);
}
void update ( int node, int l, int r, int ind) {
if(ind<l || ind>=r) return;
if(l==r-1 && l==ind) {
seg[node] += 1;
return;
}
int m = (l+r) / 2;
update(node*2+1, l, m, ind), update(node*2+2, m, r, ind);
seg[node] = seg[node*2+1] + seg[node*2+2];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
long long n,p, ans = 0, ind = 0; cin>>n;
for(int i=0; i<n; i++) cin>>a[i];
cin>>p;
vector<pair<long long,int>> st;
st.push_back({p,n});
for(int i=0; i<n; i++) {
a[i] += (i? a[i-1]:0);
long long x = a[i] - p*i;
st.push_back({x,i});
}
sort(st.begin(),st.end());
val[st[0].second] = 0;
for(int i=1; i<st.size(); i++) {
if(st[i].first==st[i-1].first) { val[st[i].second] = val[st[i-1].second]; continue; }
ind++;
val[st[i].second] = ind;
}
st.clear();
int pw = (1<<(__lg(ind-1)+1));
update(0,0,pw, val[n]);
for(int i=0; i<n; i++) {
long long x = val[i];
ans += get(0,0,pw, x);
update(0,0,pw,x);
}
cout<<ans;
return 0;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=1; i<st.size(); i++) {
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4816 KB |
Output is correct |
4 |
Correct |
417 ms |
45804 KB |
Output is correct |
5 |
Correct |
220 ms |
27688 KB |
Output is correct |
6 |
Correct |
351 ms |
44056 KB |
Output is correct |
7 |
Correct |
369 ms |
44304 KB |
Output is correct |
8 |
Correct |
320 ms |
41224 KB |
Output is correct |
9 |
Correct |
405 ms |
46768 KB |
Output is correct |
10 |
Correct |
381 ms |
45028 KB |
Output is correct |