• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 705C Thor (模拟+STL)

题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知。

析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记是哪个应用产生的,用set来记录是第几个通知.

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
queue<int> q[maxn];
set<int> sets;
set<int> :: iterator it;

int main(){
    scanf("%d %d", &n, &m);
    int ans = 0, cnt = 0, x, y;
    for(int i = 0; i < m; ++i){
        scanf("%d %d", &x, &y);
        if(1 == x){
            q[y].push(cnt);
            sets.insert(cnt++);
            ++ans;
        }
        else if(2 == x){
            while(!q[y].empty()){
                int u = q[y].front();  q[y].pop();
                if(sets.count(u)){
                    --ans;
                    sets.erase(u);
                }
            }
        }
        else if(3 == x){
            for(it = sets.begin(); it != sets.end(); ){
                if(*it < y){
                    sets.erase(it++);
                    --ans;
                }
                else break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

posted on 2016-08-08 10:39  dwtfukgv  阅读(371)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3