제출 #927689

#제출 시각아이디문제언어결과실행 시간메모리
927689koukirocksAdvertisement 2 (JOI23_ho_t2)C++17
59 / 100
2064 ms6748 KiB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MAX=5e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;

int n;
pii res[MAX]; // power,pos

int main() {
	speed;
	cin>>n;
	for (int i=0;i<n;i++) {
		cin>>res[i].second>>res[i].first;
	}
	sort(res,res+n);
	set<pii> rh,lh;
	rh.insert({res[n-1].second,res[n-1].first});
	lh.insert({res[n-1].second,res[n-1].first});
	int ans=1;
	for (int i=n-2;i>=0;i--) {
		auto it=rh.lower_bound(make_pair(res[i].second,0));
		if (it!=rh.end()) {
			auto [pos,pwr]=*it;
			if (pos-res[i].second<=pwr-res[i].first) continue;
		}
		it=lh.upper_bound(make_pair(res[i].second,0));
		if (it!=lh.begin()) {
			auto [pos,pwr]=*prev(it);
			if (res[i].second-pos<=pwr-res[i].first) continue;
		}
		ans++;
		it=rh.insert({res[i].second,res[i].first}).first;
		while (it!=rh.begin()) {
			it--;
			auto [pos,pwr]=*it;
			if (res[i].second-pos<=res[i].first-pwr) {
				it=rh.erase(it);
			}
		}
		it=lh.insert({res[i].second,res[i].first}).first;
		while (it!=prev(lh.end())) {
			it++;
			auto [pos,pwr]=*it;
			if (pos-res[i].second<=res[i].first-pwr) {
				it=lh.erase(it);
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...