秋实大哥与战争
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Submit Status
男儿何不带吴钩,收取关山五十州。
征战天下是秋实大哥一生的梦想,所以今天他又在练习一个对战游戏。
秋实大哥命令所有士兵从左到右排成了一行来抵挡敌人的攻击。
敌方每一次会攻击一个士兵,这个士兵就会阵亡,整个阵列就会从这个位置断开;同时有的时候已阵亡的士兵会受人赢气息感染而复活。
秋实大哥想知道某一时刻某一个士兵所在的阵列的长度是多少。
Input
第一行包含两个整数nn,mm,表示秋实大哥的士兵数目和接下来发生的事件数目。
接下来mm行,每一行是以下三种事件之一:
0 x : 表示x位置的士兵受到攻击阵亡
1 x : 表示x位置的士兵受人赢气息感染复活
2 x : 秋实大哥想知道第x个士兵所在阵列的长度
1≤n,m≤1000001≤n,m≤100000,1≤x≤n。1≤x≤n。
Output
对于每一个22 xx事件,输出对应的答案占一行。
Sample input and output
Sample Input | Sample Output |
---|---|
5 3 |
5 |
#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(), S.insert(n + );
for(int i = ; i <= m; i++){
scanf("%d %d", &c, &x);
if(c == ) S.insert(x);
else if(c == ) S.erase(x);
else{
if(S.count(x)) puts("");
else{
int l = *--S.lower_bound(x);
int r = *S.lower_bound(x);
printf("%d\n", r - l - );
}
}
}
}
int main(){
int n, m;
while(scanf("%d %d", &n, &m) == ){
Work(n, m);
}
}