E

秋实大哥与战争

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

男儿何不带吴钩,收取关山五十州。

征战天下是秋实大哥一生的梦想,所以今天他又在练习一个对战游戏。

秋实大哥命令所有士兵从左到右排成了一行来抵挡敌人的攻击。

敌方每一次会攻击一个士兵,这个士兵就会阵亡,整个阵列就会从这个位置断开;同时有的时候已阵亡的士兵会受人赢气息感染而复活。

秋实大哥想知道某一时刻某一个士兵所在的阵列的长度是多少。

Input

第一行包含两个整数nn,mm,表示秋实大哥的士兵数目和接下来发生的事件数目。

接下来mm行,每一行是以下三种事件之一:

0 x : 表示x位置的士兵受到攻击阵亡
1 x : 表示x位置的士兵受人赢气息感染复活
2 x : 秋实大哥想知道第x个士兵所在阵列的长度

1nm1000001≤n,m≤100000,1xn1≤x≤n。

Output

对于每一个2xx事件,输出对应的答案占一行。

Sample input and output

Sample InputSample Output
5 3
2 2
0 3
2 2
5
2
#pragma GCC diagnostic error "-std=c++11"
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#include <typeinfo>

using namespace std;

void Work(int n, int m){
    set<int> S;
    int c, x;
    S.insert(0), S.insert(n + 1);
    for(int i = 1; i <= m; i++){
        scanf("%d %d", &c, &x);
        if(c == 0) S.insert(x);
        else if(c == 1) S.erase(x);
        else{
            if(S.count(x)) puts("0");
            else{
                int l = *--S.lower_bound(x);
                int r = *S.lower_bound(x);
                printf("%d
", r - l - 1);
            }
        }
    }
}
int main(){
    int n, m;
    while(scanf("%d %d", &n, &m) == 2){
        Work(n, m);
    }
}
原文地址:https://www.cnblogs.com/Pretty9/p/7422295.html