📄 3699448_tle.cc
字号:
#include <set>
#include <stdio.h>
#include <algorithm>
using namespace std;
set <int> s;
set <int>::iterator it;
int tmd[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;
it = s.begin();
while ((it = upper_bound(it, s.end(), tmp)) != s.end())
{
int nd = *it;
int tn = nd % n;
if (tn < r || (tn == r && tmd[tn] > g))
{
r = tn;
g = tmd[tn];
}
tmp = (nd / n + 1 ) * n;
}
printf("%d\n", g);
}
}
puts("");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -