Submission #343444

# Submission time Handle Problem Language Result Execution time Memory
343444 2021-01-03T23:43:46 Z sofapuden Sails (IOI07_sails) C++14
25 / 100
66 ms 4696 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

vector<ll> seg(4e5+5,0);

void add(int l, int r, int p, int lb, int rb){
	if(l > rb || r < lb)return;
	if(l >= lb && r <= rb){
		seg[p]++;
		return;
	}
	int mid = (l+r)>>1;
	add(l,mid,p<<1,lb,rb);
	add(mid+1,r,(p<<1)+1,lb,rb);
}

ll ch(int l, int r, int p, int x){
	if(l > x || r < x)return 0;
	if(l == x && r == x)return seg[p];
	int mid = (l+r)>>1;
	return seg[p]+ch(l,mid,p<<1,x)+ch(mid+1,r,(p<<1)+1,x);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; cin >> n;
	vector<array<int,2>> v(n);
	for(auto &x : v)cin >> x[0] >> x[1];
	for(int i = 0; i < n; ++i){
		add(0,100000,1,v[i][0]-v[i][1]+1,v[i][0]);
	}
	vector<int> am(100001);
	for(int i = 0; i < 100001; ++i){
		am[i] = ch(0,100000,1,i);
	}
	int l = 1, r = 100000;
	ll bes = LONG_LONG_MAX;
	while(l <= r){
		ll cu = 0;
		int mid = (l+r)>>1;
		ll res = 0;
		for(int i = 100000; i >= 1; --i){
			if(res+am[i] >= mid){
				res -= (mid-am[i]);
				cu+=((mid)*(mid-1))/2;
			}
			else{
				cu+=((am[i]+res)*(am[i]+res-1))/2;
				res = 0;
			}
		}
		if(res){
			cu-=((mid)*(mid-1)/2);
			cu+=((mid+res)*(mid+res-1))/2;
			bes = min(bes,cu);
			l = mid+1;
		}
		else{
			r = mid-1;
			bes = min(bes,cu);
		}
	}
	cout << bes << "\n";			
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4096 KB Output is correct
2 Correct 19 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3820 KB Output is correct
2 Correct 18 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3820 KB Output is correct
2 Correct 19 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 3948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 3820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 4224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4076 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 4332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 4588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 4616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -