只过了50, 为什么?
查看原帖
只过了50, 为什么?
683727
_Luli楼主2023/8/2 09:48
#include <bits/stdc++.h>
#define int long long

using namespace std;

void solved()
{
	int n, m;
	cin >> n >> m;
	
	vector<pair<int, int>> a(m + 1);
	for (int i = 1; i <= m; i ++ )
	{
		int x, y;
		cin >> x >> y;
		a[i] = {x, y};
	} 	
	
	int ans = 0;
	vector<pair<int, int>> l;
	for (int i = m; i >= 1; i -- )
	{
		ans ++;
		if (i == m) 
		{
			;
		}
		else
		{
			int h, k;
			h = l[0].first, k = l[0].second;
			for (auto [x, y] : l)
			{
	
				if (x > k)
				{
					h = x; 
					k = y;
				}
				else k = max(k, y);

				if (h <= a[i].first && k >= a[i].second)
				{
					ans --;
					break;
				}
			}
			
		}
		l.push_back(a[i]);
		sort(l.begin(), l.end());
	}

	cout << ans;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int T = 1;
	// cin >> T;
	while (T -- )
	{
		solved();
	}

	return 0;
}
2023/8/2 09:48
加载中...