Language: C++

#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

const int N = 2e5 + 5;
typedef bool boolean
#define pii pair<int, int>

int n, m;
pii seg[N];
int uf[N];
priority_queue<int, vector<int>, greater<int>> Q;
int find(int x) {
	return uf[x] == x ? x : (uf[x] = find(uf[x]));	
}
void unit(int x, int y) {
	x = find(x), y = find(y);
	if (x > y)
		swap(x, y);
	if (x ^ y)
		uf[x] = y;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, l, r; i <= n; i++) {
		scanf("%d%d", &l, &r);
		seg[i] = pii(l, r);
	}
	sort(seg + 1, seg + n + 1);
	uf[0] = 1;
	for (int i = 1; i <= m + 1; i++) {
		uf[i] = i;
	}
	pii *p = seg + 1, *_p = seg + n + 1;
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		if (i && find(i) == i) {
			Q.push(0);
		} else if (i) {
			Q.push(i);
		}
		while (p != _p && p->first == i) {
			int R = p->second;
			boolean suc = false;
			if (!Q.empty()) {
				int tp = Q.top();
				if (tp < R) {
					int p = find(tp);
					if (p <= m) {
						unit(p, p + 1);
						Q.pop();
						Q.push(R);
						ans++;
						suc = true;
					}
				}
			}
			if (!suc) {
				int p = find(R);
				if (p <= m) {
					unit(p, p + 1);
					ans++;
					suc = true;
				}
			}
			p++;
		}
	}
	printf("%d\n", n - ans);
	return 0;
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 2e5 + 5;

#define pii pair<int, int>

int n, m;
pii seg[N];
int uf[N];
priority_queue<int, vector<int>, greater<int>> Q;
int find(int x) {
	return uf[x] == x ? x : (uf[x] = find(uf[x]));	
}
void unit(int x, int y) {
	x = find(x), y = find(y);
	if (x > y)
		swap(x, y);
	if (x ^ y)
		uf[x] = y;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, l, r; i <= n; i++) {
		scanf("%d%d", &l, &r);
		seg[i] = pii(l, r);
	}
	sort(seg + 1, seg + n + 1);
	uf[0] = 1;
	for (int i = 1; i <= m + 1; i++) {
		uf[i] = i;
	}
	pii *p = seg + 1, *_p = seg + n + 1;
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		if (i && find(i) == i) {
			Q.push(0);
		} else if (i) {
			Q.push(i);
		}
		while (p != _p && p->first == i) {
			int R = p->second;
			boolean suc = false;
			if (!Q.empty()) {
				int tp = Q.top();
				if (tp < R) {
					int p = find(tp);
					if (p <= m) {
						unit(p, p + 1);
						Q.pop();
						Q.push(R);
						ans++;
						suc = true;
					}
				}
			}
			if (!suc) {
				int p = find(R);
				if (p <= m) {
					unit(p, p + 1);
					ans++;
					suc = true;
				}
			}
			p++;
		}
	}
	printf("%d\n", n - ans);
	return 0;
}


Compiler output:
a.cc:11:1: error: expected initializer before 'int'
   11 | int n, m;
      | ^~~
a.cc: In function 'int main()':
a.cc:27:24: error: 'n' was not declared in this scope
   27 |         scanf("%d%d", &n, &m);
      |                        ^
a.cc:27:28: error: 'm' was not declared in this scope; did you mean 'tm'?
   27 |         scanf("%d%d", &n, &m);
      |                            ^
      |                            tm
a.cc:47:25: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   47 |                         boolean suc = false;
      |                         ^~~~~~~
      |                         bool
a.cc:57:49: error: 'suc' was not declared in this scope
   57 |                                                 suc = true;
      |                                                 ^~~
a.cc:61:30: error: 'suc' was not declared in this scope
   61 |                         if (!suc) {
      |                              ^~~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/assert.h:66:1: error: expected unqualified-id before string constant
   66 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
/usr/include/setjmp.h:27:1: error: expected unqualified-id before string constant
   27 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:39,
                 from a.cc:74:
/usr/include/c++/14/csetjmp:55:1: error: 'namespace' definition is not allowed here
   55 | namespace std
      | ^~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:40:
/usr/include/c++/14/cstdarg:53:1: error: 'namespace' definition is not allowed here
   53 | namespace std
      | ^~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:45:
/usr/include/c++/14/cstdint:48:1: error: 'namespace' definition is not allowed here
   48 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/bitset:71:15: error: expected '=' before '__attribute__'
   71 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bitset:71:15: error: expected identifier before '__attribute__'
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bitset:71:14: error: expected ';' before '__attribute__'
   71 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bitset:72:1: error: expected primary-expression before '{' token
   72 | {
      | ^
/usr/include/c++/14/bitset:1710:15: error: expected '=' before '__attribute__'
 1710 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bitset:1710:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bitset:1710:14: error: expected ';' before '__attribute__'
 1710 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bitset:1711:1: error: expected primary-expression before '{' token
 1711 | {
      | ^
/usr/include/c++/14/bits/std_function.h:45:15: error: expected '=' before '__attribute__'
   45 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/std_function.h:45:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/std_function.h:45:14: error: expected ';' before '__attribute__'
   45 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/std_function.h:46:1: error: expected primary-expression before '{' token
   46 | {
      | ^
In file included from /usr/include/c++/14/bits/hashtable_policy.h:38,
                 from /usr/include/c++/14/bits/hashtable.h:35,
                 from /usr/include/c++/14/bits/unordered_map.h:33,
                 from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63:
/usr/include/c++/14/ext/aligned_buffer.h:40:1: error: 'namespace' definition is not allowed here
   40 | namespace __gnu_cxx
      | ^~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:42:15: error: expected '=' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:42:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/hashtable_policy.h:42:14: error: expected ';' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/hashtable_policy.h:43:1: error: expected primary-expression before '{' token
   43 | {
      | ^
/usr/include/c++/14/bits/enable_special_members.h:37:15: error: expected '=' before '__attribute__'
   37 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/enable_special_members.h:37:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/bits/hashtable.h:36:
/usr/include/c++/14/bits/enable_special_members.h:37:14: error: expected ';' before '__attribute__'
   37 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/enable_special_members.h:38:1: error: expected primary-expression before '{' token
   38 | {
      | ^
/usr/include/c++/14/bits/node_handle.h:44:15: error: expected '=' before '__attribute__'
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/node_handle.h:44:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/bits/hashtable.h:39:
/usr/include/c++/14/bits/node_handle.h:44:14: error: expected ';' before '__attribute__'
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/node_handle.h:45:1: error: expected primary-expression before '{' token
   45 | {
      | ^
/usr/include/c++/14/bits/hashtable.h:42:15: error: expected '=' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:42:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/hashtable.h:42:14: error: expected ';' before '__attribute__'
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/hashtable.h:43:1: error: expected primary-expression before '{' token
   43 | {
      | ^
/usr/include/c++/14/bits/unordered_map.h:38:15: error: expected '=' before '__attribute__'
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:38:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/unordered_map.h:38:14: error: expected ';' before '__attribute__'
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/unordered_map.h:39:1: error: expected primary-expression before '{' token
   39 | {
      | ^
In file included from /usr/include/c++/14/unordered_map:43:
/usr/include/c++/14/bits/erase_if.h:39:1: error: 'namespace' definition is not allowed here
   39 | namespace std
      | ^~~~~~~~~
/usr/include/c++/14/unordered_map:60:15: error: expected '=' before '__attribute__'
   60 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/unordered_map:60:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/unordered_map:60:14: error: expected ';' before '__attribute__'
   60 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/unordered_map:61:1: error: expected primary-expression before '{' token
   61 | {
      | ^
/usr/include/c++/14/array:54:15: error: expected '=' before '__attribute__'
   54 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/array:54:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/functional:65:
/usr/include/c++/14/array:54:14: error: expected ';' before '__attribute__'
   54 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/array:55:1: error: expected primary-expression before '{' token
   55 | {
      | ^
/usr/include/c++/14/functional:92:15: error: expected '=' before '__attribute__'
   92 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/functional:92:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/functional:92:14: error: expected ';' before '__attribute__'
   92 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/functional:93:1: error: expected primary-expression before '{' token
   93 | {
      | ^
/usr/include/c++/14/bits/stream_iterator.h:40:15: error: expected '=' before '__attribute__'
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stream_iterator.h:40:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/iterator:65,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/stream_iterator.h:40:14: error: expected ';' before '__attribute__'
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stream_iterator.h:41:1: error: expected primary-expression before '{' token