数据过水
查看原帖
数据过水
568434
liuchuliang666楼主2024/11/3 14:39

暴力居然过了

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 10;
int n, m, rst[MAXN];
bool book[MAXN];
int insert(int x)
{
	for(int i = 1; i <= n - x + 1 ; i++)
		if(rst[i] - i + 1 >= x)
		{
			for(int j = i; j <= i + x - 1; j++)
			{
				book[j] = 1;
				rst[j] = j - 1;
			}
			for(int j = i - 1; j > 0 && !book[j]; j--)
				rst[j] = i - 1;
			return i;
		}
	return 0;
}
void remove(int x, int y)
{
	for(int i = y ; i >= x; i--)
		book[i] = 0, rst[i] = rst[i + 1];
	for(int i = x - 1; i > 0 && !book[i]; i--)
		rst[i] = rst[x];
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("room.in", "r", stdin);
//	freopen("room.out", "w", stdout);
	int opt, x, y;
	cin >> n >> m;
	fill(rst + 1, rst + 2 + n, n);
	while(m--)
	{
		cin >> opt;
		switch(opt)
		{
			case 1:
				cin >> x;
				cout << insert(x) << endl;
				break;
			case 2:
				cin >> x >> y;
				remove(x, x + y - 1);
		}
	}
	return 0;
}

2024/11/3 14:39
加载中...