3699444_ce.cc
来自「北大大牛代码 1240道题的原代码 超级权威」· CC 代码 · 共 58 行
CC
58 行
#include <set>
#include <stdio.h>
#include <algorithm>
using namespace std;
set <int> s;
set <int>::iterator it;
int tm[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);
tm[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 && tm[tn] > g))
{
r = tn;
g = tm[tn];
}
tmp = (nd / n + 1 ) * n;
}
printf("%d\n", g);
}
}
puts("");
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?