📄 3713866_tle.cc
字号:
#include <set>
#include <stdio.h>
#include <algorithm>
using namespace std;
set <int> s;
set <int>::iterator it;
int tmd[500001];
int num[500001];
int main()
{
int t, k, n;
char str[2];
int r, g;
int cas = 1;
while (scanf("%d", &t) == 1 && t != 0)
{
printf("Case %d:\n", cas++);
k = 1;
s.clear();
while (t-- != 0)
{
scanf("%s%d", str, &n);
if (str[0] == 'B')
{
s.insert(n);
tmd[n] = k++;
}
else
{
if (s.empty())
{
puts("-1");
continue;
}
r = 500000;g = 0;
int tmp = 0;
int c;
for (c = 0, it = s.begin(); it != s.end(); ++it, c++)
{
num[c] = (*it);
}
int min = 0, max, mid;
while (true)
{
max = c;
while (min < max)
{
mid = (min + max) >> 1;
if (num[mid] <= tmp)
min = mid + 1;
else
max = mid;
}
if (min >= c)
break;
int nd = num[min];
int tn = nd % n;
if (tn < r || (tn == r && tmd[nd] > g))
{
r = tn;
g = tmd[nd];
}
tmp = (nd / n + 1 ) * n;
}
printf("%d\n", g);
}
}
puts("");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -