# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
384224 |
2021-03-31T19:53:20 Z |
SavicS |
Vudu (COCI15_vudu) |
C++14 |
|
808 ms |
50124 KB |
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1000005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n;
ll P;
ll niz[maxn];
ll pref[maxn];
ll bor[4 * maxn];
void build(int v, int tl, int tr) {
if(tl == tr) {
bor[v] = niz[tl];
return;
}
int mid = (tl + tr) / 2;
build(v * 2, tl, mid);
build(v * 2 + 1, mid + 1, tr);
bor[v] = bor[v * 2] + bor[v * 2 + 1];
}
void update(int v, int tl, int tr, int pos, ll val) {
if(tl == tr) {
bor[v] += val;
return;
}
int mid = (tl + tr) / 2;
if(pos <= mid)update(v * 2, tl, mid, pos, val);
else update(v * 2 + 1, mid + 1, tr, pos, val);
bor[v] = bor[v * 2] + bor[v * 2 + 1];
}
ll kveri(int v, int tl, int tr, int l, int r) {
if(tl > r || tr < l)return 0;
if(tl >= l && tr <= r)return bor[v];
int mid = (tl + tr) / 2;
return kveri(v * 2, tl, mid, l, r) + kveri(v * 2 + 1, mid + 1, tr, l, r);
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n;
ff(i,1,n)cin >> niz[i];
cin >> P;
ff(i,1,n)pref[i] = pref[i - 1] + niz[i];
vector<ll> all;
ff(i,1,n)all.pb(pref[i] - 1ll * P * i);
sort(all(all));
all.erase(unique(all(all)), all.end());
auto Fnd = [&](ll x) {
return lower_bound(all(all), x) - all.begin() + 1;
};
ll rez = 0;
ff(i,1,n) {
int x = Fnd(pref[i] - 1ll * i * P);
if(pref[i] - 1ll * i * P >= 0)rez += 1;
rez += kveri(1,1,n,1,x);
update(1,1,n,x,1);
}
cout << rez << endl;
return 0;
}
/**
3
1 2 3
3
// probati bojenje sahovski ili slicno
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
748 KB |
Output is correct |
3 |
Correct |
4 ms |
748 KB |
Output is correct |
4 |
Correct |
808 ms |
48972 KB |
Output is correct |
5 |
Correct |
412 ms |
35148 KB |
Output is correct |
6 |
Correct |
673 ms |
45388 KB |
Output is correct |
7 |
Correct |
680 ms |
46540 KB |
Output is correct |
8 |
Correct |
601 ms |
42700 KB |
Output is correct |
9 |
Correct |
763 ms |
50124 KB |
Output is correct |
10 |
Correct |
671 ms |
45740 KB |
Output is correct |