queue

题目连接:https://www.bnuoj.com/v3/contest_show.php?cid=9057#problem/K

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 #include<cctype>
 5 #include<algorithm>
 6 #include<map>
 7 #include<string>
 8 #include<iostream>
 9 using namespace std;
10 int t,n;
11 map<string, int> p;
12 string c,s;
13 int vis[100020];
14 int main()
15 {
16     scanf("%d",&t);
17     while(t--)
18     {
19         int cnt=0;
20         int ans=0;
21         queue<int> q;
22         while(!q.empty()) q.pop();
23         scanf("%d",&n);
24         p.clear();
25         memset(vis,0,sizeof(vis));
26         for(int i=0;i<n;i++)
27         {
28             cin>>c>>s;
29 
30             if(c[0]=='i')
31             {
32                 p[s]=cnt++;
33                 q.push(p[s]);
34             }
35             else
36             {
37                 int x=q.front();
38                 while(vis[x]) {q.pop();x=q.front();}
39                 if(x==p[s]) q.pop();
40                 else {
41                 vis[p[s]]=1;
42                 ans++;
43                 }
44             }
45         }
46         cout<<n/2-ans<<endl;
47     }
48 }
原文地址:https://www.cnblogs.com/yijiull/p/6753555.html