Submission #48438

#TimeUsernameProblemLanguageResultExecution timeMemory
48438aleksamiVudu (COCI15_vudu)C++14
56 / 140
1065 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 1000005 typedef long long ll; ll a[MAXN]; int tree[4*MAXN]; vector <ll> v; void update(int node,int left,int right,int idx,int val) { if(left==right) { tree[node]+=val; return ; } int mid=left+right>>1; if(idx <= mid)update(node*2,left,mid,idx,val); if(idx > mid)update(node*2+1,mid+1,right,idx,val); tree[node]=tree[node*2]+tree[node*2+1]; } int query(int node,int left,int right,int l,int r) { if(left >= l && right <= r)return tree[node]; int mid = left+right>>1; int ans=0; if(l <= mid)ans+=query(node*2,left,mid,l,r); if(r > mid)ans+=query(node*2+1,mid+1,right,l,r); return ans; } set <ll> st; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } ll p; cin >> p; for(int i = 1; i <= n; i++) { a[i]-=p; } //v.push_back(0LL); st.insert(0LL); for(int i = 1; i <= n; i++) { a[i]+=a[i-1]; st.insert(a[i]);//v.push_back(a[i]); } for(auto x:st)v.push_back(x); //sort(v.begin(),v.end()); ll ans=0; for(int i = 0; i <= n; i++) { a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin(); if(i!=0)update(1,0,v.size()-1,a[i-1],1); ans += 1LL*query(1,0,v.size()-1,0,a[i]); } cout << ans; return 0; }

Compilation message (stderr)

vudu.cpp: In function 'void update(int, int, int, int, int)':
vudu.cpp:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=left+right>>1;
          ~~~~^~~~~~
vudu.cpp: In function 'int query(int, int, int, int, int)':
vudu.cpp:25:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = left+right>>1;
            ~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...