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;
#define int long long
int N = 1<<17;
vector<int> bpro(2*N, 0);
vector<int> bmin(2*N, 0);
void update(int curr, int l, int r, int ll, int rr, int p)
{
if (l >= rr || r <= ll)
{
bpro[curr]+=p;
bmin[curr]+=p;
return;
}
if (l >= ll && r <= rr)
{
bpro[curr]+=p+1;
bmin[curr]+=p+1;
return;
}
p += bpro[curr];
bpro[curr] = 0;
int m = (l+r)/2;
update(curr*2, l, m, ll, rr, p);
update(curr*2+1, m, r, ll, rr, p);
bmin[curr] = min(bmin[curr*2], bmin[curr*2+1]);
}
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
cin >> n;
vector<vector<int>> height(1e5+1);
int left = 0;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
height[a].push_back(b);
left += b;
}
int sol = 0;
int upper = 1e5;
for (int i = 1e5; i > 0; i--)
{
sort(height[i].begin(), height[i].end(), greater<int>());
for (int ele:height[i])
{
int b = ceil(left/(double)upper);
int uh;
do
{
uh = bmin[upper+N];
int curr = upper+N;
while (curr>1)
{
curr/=2;
uh+=bpro[curr];
}
if (uh >= b)
{
upper--;
left -= uh;
}
}
while (uh >=b);
//int s = search(1, 0, N, i+1, b, 0)+1;
//cout << bmin[N+s-1] << " " << s-ele << " " << s << endl;
update(1, 0, N, upper-ele+1, upper+1, 0);
}
int h = bmin[i+N];
int curr = i+N;
while (curr>1)
{
curr/=2;
h+=bpro[curr];
}
sol += (h*(h-1))/2;
if (upper == i)
{
left -= h;
upper--;
}
}
cout << sol << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |