67112023-12-17 18:22:34111Rendezéscpp17Wrong answer 7/4050ms31472 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

void join(vector<pii>& r) {
	if (r.empty()) {
		return;
	}
	int j = 0;
	for (int i = 1; i < r.size(); i++) {
		if (r[j].second >= r[i].first) {
			r[j].second = r[i].second;
		}
		else {
			j++;
			r[j] = r[i];
		}
	}
	r.resize(j + 1);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be1.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, M;
	cin >> N >> M;
	vector<int> v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
	}
	vector<pii> w(M);
	for (int i = 0; i < M; i++) {
		cin >> w[i].first >> w[i].second;
	}
	sort(w.begin(), w.end());
	join(w);
	for (auto [a, b] : w) {
		sort(v.begin() + a, v.begin() + b + 1);
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += v[i] == i;
	}
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/40
1Accepted0/03ms1832 KiB
2Wrong answer0/09ms2968 KiB
3Accepted2/23ms2544 KiB
4Wrong answer0/23ms2720 KiB
5Wrong answer0/23ms2784 KiB
6Wrong answer0/23ms2788 KiB
7Wrong answer0/23ms3152 KiB
8Wrong answer0/23ms3264 KiB
9Wrong answer0/23ms3520 KiB
10Wrong answer0/23ms3504 KiB
11Wrong answer0/250ms9988 KiB
12Accepted2/248ms11808 KiB
13Accepted2/250ms13648 KiB
14Accepted1/148ms15376 KiB
15Wrong answer0/248ms17244 KiB
16Wrong answer0/248ms18984 KiB
17Wrong answer0/248ms20812 KiB
18Wrong answer0/248ms22732 KiB
19Wrong answer0/250ms24452 KiB
20Wrong answer0/148ms26144 KiB
21Wrong answer0/248ms27876 KiB
22Wrong answer0/248ms29596 KiB
23Wrong answer0/248ms31472 KiB