Submission #977003

#TimeUsernameProblemLanguageResultExecution timeMemory
977003SeenSiravitVudu (COCI15_vudu)C++14
140 / 140
220 ms55012 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const int mxN = 1e6 + 5; struct DATA { int idx; ll val; }; int n; ll a[mxN]; DATA b[mxN]; ll p; int fw[mxN]; vector<DATA> tmp; int mp[mxN]; bool cmp(DATA x , DATA y){ if(x.val == y.val) return x.idx < y.idx; return x.val < y.val; } void update(int idx , int val){ for(int i=idx;i<mxN;i += (i & -i)) fw[i] += val; } ll query(int idx){ ll res = 0; for(int i=idx;i>0;i -= (i & -i)) res += fw[i]; return res; } int main(){ ios::sync_with_stdio(0),cin.tie(0); cin>> n; for(int i=1;i<=n;i++) cin>> a[i] , a[i] += a[i-1]; // for(int i=1;i<=n;i++) cout<< a[i] << " "; // cout<< "\n"; cin>> p; tmp.push_back({0,0}); for(int i=1;i<=n;i++) b[i].val = a[i] - p*i , b[i].idx = i , tmp.push_back(b[i]); // for(int i=1;i<=n;i++) cout<< b[i] << " "; // cout<< "\n\n"; sort(tmp.begin() , tmp.end() , cmp); // for(auto elem : tmp) cout<< elem.idx << " " << elem.val << " , "; // cout<< "\n"; int id = 1; for(auto elem : tmp){ mp[elem.idx] = id; id++; } ll ans = 0; update(mp[0] , 1); for(int i=1;i<=n;i++){ int cnt = query(mp[b[i].idx]); // cout<< "\ncnt = " << cnt << " "; // cout<< cnt << "\n\n"; ans += cnt; update(mp[i] , 1); } cout<< ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...