Submission #1135584

#TimeUsernameProblemLanguageResultExecution timeMemory
1135584yellowtoadAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
155 ms35864 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
#define int long long
using namespace std;

int n, suf[500010], ans, ok[500010], maxx = -1e18;
pair<int,int> a[500010], b[500010];
vector<int> v;
vector<pair<int,int>> aa, bb;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].f >> a[i].s;
		b[i] = a[i];
		a[i].s -= a[i].f;
		b[i].s += b[i].f;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for (int i = 1; i <= n; i++) if (a[i].f != a[i+1].f) aa.push_back(a[i]), bb.push_back(b[i]);
	for (int i = 0; i < aa.size(); i++) ok[i] = 1;
	for (int i = 0; i < bb.size(); i++) {
		if (maxx >= bb[i].s) ok[i] = 0;
		maxx = max(maxx,bb[i].s);
	}
	maxx = -1e18;
	for (int i = aa.size()-1; i >= 0; i--) {
		if (maxx >= aa[i].s) ok[i] = 0;
		maxx = max(maxx,aa[i].s);
	}
	for (int i = 0; i < aa.size(); i++) ans += ok[i];
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...