【SSL 1503】WING
题目大意:
给几个操作,每次操作给出一个只包含 ‘W’、‘I’、‘N’、‘G’ 的字符串加入一个库里,再给出几个询问,每次询问求出被查询串最早第几次加入库。
正文:
神怖题,开个桶记录某字符第几次入库。
代码:
inline int read(){
char ch = getchar();
int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(int x){
if (x < 0) x = ~x + 1, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
char s[N];
int n,m,ans,t;
int a[N][4];
int getnum(char ch)
{
if (ch=='W') return 0;
if (ch=='I') return 1;
if (ch=='N') return 2;
return 3;
}
int main()
{
n = read(), m = read();
for (int i=1;i<=m;i++)
{
int op = read();
for (int j = 1; j <= n; j++)
s[j] = getchar();
if (op)
{
ans=0;
for (int j=1;j<=n;j++)
{
if (!a[j][getnum(s[j])]) { ans=-1;break;}
ans=max(ans,a[j][getnum(s[j])]);
}
write(ans);
putchar(10);
}
else
{
t++;
for (int j=1;j<=n;j++) if (!a[j][getnum(s[j])]) a[j][getnum(s[j])]=t;
}
}
}