Submission #256602

#TimeUsernameProblemLanguageResultExecution timeMemory
256602amiratouVudu (COCI15_vudu)C++14
140 / 140
578 ms23932 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define fi first #define se second #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl; #define sep() cerr << "--------------------" << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ld long double #define ll long long //#define int ll #define ii pair<ll,int> #define v vector<int> #define vii vector<ii> #define vv vector<vector<int> > #define mp make_pair #define INF 1000000000 #define pb push_back #define EPS 1e-9 const int MOD = 1000000007; // 998244353 int A[1000005],fen[1000005],n,k,idx=1; ll h,ans; void upd(int i,int val){ for (; i <= n+1; i+=(i&(-i))) fen[i]+=val; } int get(int i){ int l=0; for (; i >= 1; i-=(i&(-i)))l+=fen[i]; return l; } int sum(int a,int b){ return get(b)-get(a-1); } int32_t main(){ boost; cin>>n; vii vec(n+1); vec[n].fi=0; for (int i = 0; i < n; ++i) cin>>A[i]; cin>>k; for (int i = 0; i < n; ++i) { h+=A[i]-k; vec[i]={h,INF}; } sort(all(vec)); for (int i = 0; i < sz(vec);) { int j=i,cnt=0; if(!vec[i].fi)cnt--; while(j<sz(vec) && vec[j].fi==vec[i].fi) cnt++,j++; vec[i].se=idx; if(cnt)upd(idx,cnt); i=j,idx++; } h=0; for (int i = 0; i < n; ++i) { int m=(*lower_bound(all(vec),ii(h,-1))).se; ans+=sum(m,n+1); h+=A[i]-k; m=(*lower_bound(all(vec),ii(h,-1))).se; upd(m,-1); } cout<<ans<<"\n"; return 0; } //do smth instead of nothing and stay organized //long long //array bounds //special cases //binary search
#Verdict Execution timeMemoryGrader output
Fetching results...