深夜写题解,我只想说内心是崩溃的。
题意:三种操作1.某APP来一个消息 2.读完APPx的所有消息 3.读完前t个消息(是前t个,包括读过的)
想法:静下心读懂题意,想好思路再做算法设计要有明确的伪代码,才能保证万无一失
set.erase(*it); 删除*it的值之后,你会发现如果你用的是for(it = st.begin(); it != st.end(); it++) ,你会发现删除一个之后会出现数据错乱!因为st.begin()的位置变了,注意~~~~!!!!!
http://codeforces.com/contest/705/problem/C
题解:
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, string> P;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MAX_N 300005
#define LOCAL
set<int> st; //all index
queue<int> que[MAX_N];
int cnt = 0;
void solve(int type, int xt)
{
if(type == 1)
{
cnt++; //the index
que[xt].push(cnt);
st.insert(cnt);
}
else
if(type == 2)
{
while(!que[xt].empty())
{
st.erase(que[xt].front());
que[xt].pop();
}
}
else
if(type == 3)
{
set<int>::iterator it;
int cntnow = 0;
for(it = st.begin(); it!=st.end(); it++) //你妈神坑~~~ 记得你st.erase()后再st.begin()就变了
{
cout << *it << " " ;
if(*it <= xt)
st.erase(*it);
else
break;
}
cout << endl;
}
}
int main()
{
#ifdef LOCAL
freopen("b:\\data.in.txt", "r", stdin);
#endif
int n, q;
scanf("%d%d", &n, &q);
for(int i = 0; i < q; i++)
{
int type, xt ; scanf("%d%d", &type, &xt);
solve(type, xt);
// printf("%d\n", st.size());
}
return 0;
}