CodeForces 705C 我被set.erase(*it)套路了

深夜写题解,我只想说内心是崩溃的。

题意:三种操作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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值