Submission #1281288

#TimeUsernameProblemLanguageResultExecution timeMemory
1281288KickingKunAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
111 ms4616 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define bigint __int128
#define emb emplace_back
#define pb push_back
#define pii pair <int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define Task ""

#define MASK(k) (1ull << k)
#define bitcnt(k) __builtin_popcount(k)
#define testBit(n, k) ((n >> k) & 1)
#define flipBit(n, k) (n ^ (1ll << k))
#define offBit(n, k) (n & ~MASK(k))
#define onBit(n, k) (n | (1ll << k))

template <class T> bool minimize(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool maximize(T &a, T b) {if (a < b) {a = b; return true;} return false;}

const int N = 5e5 + 5, lim = 60, mod = 1e9 + 7;
const ll INF = 1e18;

int n; bool source[N];
vector <pii> p;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	if (fopen(Task".inp", "r")) {
		freopen(Task".inp", "r", stdin);
		freopen(Task".out", "w", stdout);
	}

	cin >> n; p.assign(n, make_pair(0, 0));
	for (int i = 0; i < n; i++)
		cin >> p[i].fi >> p[i].se;
	sort (all(p)); p.resize(unique(all(p)) - p.begin());
	n = p.size();

	// l -> i: xi - xl <= el - ei
	// xi + ei <= xl + el

	// r -> i: xr - xi <= er - ei
	// xr - er <= xi - ei

	// for (int i = 0; i < n; i++)
	// 	for (int j = 0; j < n; j++)
	// 		if (i != j && abs(p[i].fi - p[j].fi) <= p[i].se - p[j].se)
	// 			cerr << i << ' ' << j << '\n';

	memset(source, true, sizeof source);
	for (int i = 1, ma = p[0].fi + p[0].se; i < n; i++) {
		if (p[i].fi + p[i].se <= ma) source[i] = false;
		maximize(ma, p[i].fi + p[i].se);
	}

	for (int i = n - 2, mi = p[n - 1].fi - p[n - 1].se; i >= 0; i--) {
		if (p[i].fi - p[i].se >= mi) source[i] = false;
		minimize(mi, p[i].fi - p[i].se);
	}

// 	for (int i = 0; i < n; ++i) if (source[i]) {
// 		cerr << i << ' ';
// 	}
// 	cerr << '\n';
	cout << count(source, source + n, true);
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:36:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |                 freopen(Task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |                 freopen(Task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...