# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410112 | rqi | Vudu (COCI15_vudu) | C++14 | 287 ms | 25668 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>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define ins insert
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
const int mx = 1000005;
int N;
ll a[mx];
ll P;
int bt[mx];
void upd(int pos, int val){
for(int i = pos; i < mx; i+=i&-i){
bt[i]+=val;
}
}
int sum(int pos){
int res = 0;
for(int i = pos; i > 0; i-=i&-i){
res+=bt[i];
}
return res;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> N;
for(int i = 1; i <= N; i++){
cin >> a[i];
}
cin >> P;
for(int i = 1; i <= N; i++){
a[i]-=P;
}
for(int i = 1; i <= N; i++){
a[i]+=a[i-1];
}
vi v;
for(int i = 0; i <= N; i++){
v.pb(i);
}
auto sort_func = [&](const int i, const int j){
return mp(a[i], i) < mp(a[j], j);
};
sort(all(v), sort_func);
ll ans = 0;
for(auto u: v){
//cout << u << "\n";
ans+=ll(sum(u+1));
upd(u+1, 1);
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |