Submission #669745

# Submission time Handle Problem Language Result Execution time Memory
669745 2022-12-07T08:07:53 Z Koful123 Sails (IOI07_sails) C++17
5 / 100
156 ms 3796 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int lg = 20;
struct Fenwick{	
	int n; vector<int> fw;
	Fenwick(int _n){
		fw.assign((n = _n) + 1,0);
	};
	void upd(int pos,int x){
		for(; pos <= n; pos += (pos & -pos)){
			fw[pos] += x;
		}
	}
	void upd(int l,int r,int x){
		upd(l,1), upd(r + 1,-1);
	}
	int get(int pos){
		int res = 0; for(; pos; pos -= (pos & -pos)){
			res += fw[pos];
		}
		return res;
	}
	int find(int x,int sz){
		int pos = 0;
		for(int i = lg; i >= 0; i--){
			if(pos + (1 << i) <= sz && fw[pos + (1 << i)] < x){
				pos += (1 << i);
				x -= fw[pos];
			}
		}
		return pos;
	}
};

void solve(){	

	int n;
	cin >> n;

	vector<pair<int,int>> v(n);
	for(auto &[x,y] : v){
		cin >> x >> y;
	}

	sort(rall(v));
	auto check = [&](int m,int ty){
		Fenwick fw(v[0].ff);
		for(int i = 0; i < n; i++){
			int pos = fw.find(m,v[i].ff);
			if(pos - v[i].ss + 1 <= 0) return 0ll;
			fw.upd(pos - v[i].ss + 1,pos,1);
		}	
		int res = 0;
		for(int i = 1; i <= v[0].ff; i++){
			res += fw.get(i) * (fw.get(i) - 1) / 2;
		}
		return (ty ? res : 1ll);
	};

	int l = 1,r = n;
	while(l < r){
		int m = (l + r) / 2;
		if(check(m,0)) r = m;
		else l = m + 1; 
	}		

	cout << check(l,1) << endl;
}	
 
signed main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int t = 1;
//	cin >> t;
 
	while(t--)
		solve();
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 2044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 3132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 3500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 3796 KB Output isn't correct
2 Halted 0 ms 0 KB -