QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#500604#3817. Generating PolygonsPetroTarnavskyi#RE 0ms0kbC++201.8kb2024-08-01 16:10:132024-08-01 16:10:14

Judging History

This is the latest submission verdict.

  • [2024-08-01 16:10:14]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-08-01 16:10:13]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int d, q;
	cin >> d >> q;
	set<PII> sLen, sPos;
	map<string, PII> cars;
	sLen.insert({d, 0});
	sPos.insert({0, d});
	while (q--)
	{
		char t;
		cin >> t;
		if (t == 'P')
		{
			string s;
			int l;
			cin >> s >> l;
			auto it = sLen.lower_bound({l, 0});
			int pos;
			if (it == sLen.end())
			{
				pos = -1;
			}
			else
			{
				int len = it->F;
				pos = it->S;
				sLen.erase(it);
				sPos.erase({pos, len});
				if (len - l > 0)
				{
					sLen.insert({len - l, pos + l});
					sPos.insert({pos + l, len - l});
				}
			}
			cars[s] = {l, pos};
			if (pos == -1)
				cout << "NIE\n";
			else
				cout << pos << "\n";
		}
		else
		{
			assert(t == 'O');
			string s;
			cin >> s;
			auto [l, pos] = cars[s];
			if (pos == -1)
			{
				cout << "BRAK\n";
				continue;
			}
			int newLen = l, newPos = pos;
			auto it = sPos.lower_bound({pos + l, 0});
			if (it != sPos.end() && it->F == pos + l)
			{
				newLen += it->S;
				sLen.erase({it->S, pos + l});
				it = sPos.erase(it);
			}
			if (it != sPos.begin())
			{
				it--;
				auto [posL, lenL] = *it;
				if (posL + lenL == pos)
				{
					sLen.erase({lenL, posL});
					sPos.erase(it);
					newLen += lenL;
					newPos = posL;
				}
			}
			sLen.insert({newLen, newPos});
			sPos.insert({newPos, newLen});
			cout << "OK\n";
		}
	}
	return 0;
}


詳細信息

Test #1:

score: 0
Runtime Error

input:

14 6

output:


result: