Submission #1840503


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 2e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;

struct rec {
	int x, y;
	inline bool operator < (const rec &v) {
		return (x == v.x) ? y > v.y : x < v.x;
	}
}a[maxN];

namespace Seg {
	static const int maxN = 524297;
	#define lc (x << 1)
	#define rc (x << 1 | 1)

	int mx[maxN], tag[maxN];

	void pushup(int x) {
		mx[x] = max(mx[lc], mx[rc]);
	}

	void totag(int x, int d) {
		mx[x] += d; tag[x] += d;
	}

	void pushdown(int x) {
		if (tag[x]) {
			totag(lc, tag[x]);
			totag(rc, tag[x]);
			tag[x] = 0;
		}
	}

	void build(int x, int l, int r) {
		tag[x] = 0;
		if (l == r) {
			mx[x] = l;
			return;
		}
		int mid = (l + r) >> 1;
		build(lc, l, mid);
		build(rc, mid+1, r);
		pushup(x);
	}

	void add(int x, int l, int r, int tl, int tr) {
		if (tl <= l && r <= tr) {totag(x, 1); return;}
		int mid = (l + r) >> 1;
		pushdown(x);
		if (tl <= mid) add(lc, l, mid, tl, tr);
		if (mid < tr) add(rc, mid+1, r, tl, tr);
		pushup(x);
	}

	int get(int x, int l, int r, int tl, int tr) {
		if (tl <= l && r <= tr) return mx[x];
		int mid = (l + r) >> 1;
		pushdown(x);
		if (tr <= mid) return get(lc, l, mid, tl, tr);
		if (mid < tl) return get(rc, mid+1, r, tl, tr);
		return max(get(lc, l, mid, tl, tr), get(rc, mid+1, r, tl, tr));
	}

	inline void build() {build(1, 0, m+1);}
	inline void add(int l, int r) {add(1, 0, m+1, l, r);}
	inline int get(int l, int r) {return get(1, 0, m+1, l, r);}

	#undef lc
	#undef rc
}

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) a[i].x = ri(), a[i].y = ri();
	sort(a+1, a+n+1);
	
	int res = max(n - m, 0);
	Seg::build();
	rep (i, 1, n) {
		Seg::add(1, a[i].y);
		if (a[i].x <= m) res = max(res, Seg::get(a[i].x + 1, m + 1) - a[i].x - (m + 1));
	}
	printf("%d\n", res);

	return 0;
}

Submission Info

Submission Time
Task F - Exhausted?
User acha
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 2360 Byte
Status AC
Exec Time 157 ms
Memory 5888 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 4
AC × 48
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 137 ms 5632 KB
02.txt AC 90 ms 5120 KB
03.txt AC 156 ms 5760 KB
04.txt AC 156 ms 5760 KB
05.txt AC 7 ms 3328 KB
06.txt AC 112 ms 5376 KB
07.txt AC 141 ms 4736 KB
08.txt AC 157 ms 5760 KB
09.txt AC 139 ms 4736 KB
10.txt AC 44 ms 4608 KB
11.txt AC 151 ms 5888 KB
12.txt AC 110 ms 5376 KB
13.txt AC 118 ms 3968 KB
14.txt AC 116 ms 3968 KB
15.txt AC 151 ms 5760 KB
16.txt AC 78 ms 4096 KB
17.txt AC 143 ms 5760 KB
18.txt AC 143 ms 5760 KB
19.txt AC 127 ms 5632 KB
20.txt AC 144 ms 5760 KB
21.txt AC 31 ms 4608 KB
22.txt AC 143 ms 5760 KB
23.txt AC 19 ms 2944 KB
24.txt AC 143 ms 5760 KB
25.txt AC 80 ms 5376 KB
26.txt AC 72 ms 4352 KB
27.txt AC 82 ms 5760 KB
28.txt AC 82 ms 4736 KB
29.txt AC 92 ms 5760 KB
30.txt AC 91 ms 5760 KB
31.txt AC 143 ms 5760 KB
32.txt AC 124 ms 5632 KB
33.txt AC 143 ms 5760 KB
34.txt AC 93 ms 5248 KB
35.txt AC 73 ms 4992 KB
36.txt AC 142 ms 5760 KB
37.txt AC 1 ms 2176 KB
38.txt AC 1 ms 2176 KB
39.txt AC 1 ms 2176 KB
40.txt AC 1 ms 2176 KB
41.txt AC 1 ms 2176 KB
42.txt AC 1 ms 2176 KB
43.txt AC 3 ms 4224 KB
44.txt AC 1 ms 2176 KB
s1.txt AC 1 ms 2176 KB
s2.txt AC 1 ms 2176 KB
s3.txt AC 1 ms 2176 KB
s4.txt AC 1 ms 2176 KB