QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500604 | #3817. Generating Polygons | PetroTarnavskyi# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-08-01 16:10:13 | 2024-08-01 16:10:14 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
14 6