# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
976992 | SeenSiravit | Vudu (COCI15_vudu) | C++14 | 315 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
map<int,int> mp;
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;
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";
tmp.push_back({0,0});
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;
for(int i=1;i<=n;i++){
int cnt = query(mp[b[i].idx]);
// cout<< "\ncnt = " << cnt << " ";
if(a[i]-a[i-1] >= p) cnt++;
// cout<< cnt << "\n\n";
ans += cnt;
// cout<< cnt << " ";
update(mp[i-1] , 1);
}
cout<< ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |