Submission #256582

#TimeUsernameProblemLanguageResultExecution timeMemory
256582ElyesChaabouniVudu (COCI15_vudu)C++14
0 / 140
276 ms65540 KiB
/*#pragma GCC optimize("O3") #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops")*/ #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_10 299473306 #define INF 1000000001 #define PI 3.14159265358979323846 using namespace std; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin >> n; int a[n]; //cout << n << '\n'; for(int i = 0; i < n; i++) cin >> a[i]; int p; vector<pair<long long, int> >v; cin >> p; long long sum=0, cu=0, ans=0; for(int i = n-1; i >= 0; i--) { sum+=a[i]; v.push_back(make_pair(sum-cu, i)); //cout << here[i] << ' '; cu+=p; } //cout << '\n'; sort(v.begin(), v.end()); int m[n]; for(int i = 0; i < n; i++) { m[v[i].second]=i; } int pp=1; while(pp <= n) pp*=2; cu=0; int tree[2*p+1]; for(int i = 0; i <2*p+1; i++) tree[i]=0; for(int i = p; i <= p+n-1; i++) tree[i]=1; for(int i = p-1; i >= 1; i--) tree[i]=tree[2*i]+tree[2*i+1]; sum=0; for(int i = n-1; i >= 0; i--) { vector<pair<long long, int> >::iterator it=lower_bound(v.begin(), v.end(), make_pair(p+sum-cu, -1)); if(it!=v.end()) { int x=(it-v.begin())+p, y=n-1+p; while(x <= y) { if(x%2==1) { ans+=tree[x]; x++; } if(y%2==0) { ans+=tree[y]; y--; } x/=2; y/=2; } } //cout << s.order_of_key(*s.lower_bound(make_pair(p+pr-cu, -1))) << '\n'; sum+=a[i]; int x=m[i]+p; while(x >= 1) { tree[x]--; x/=2; } cu+=p; } cout << ans << '\n'; //printf("%lld", ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...