E - 秋實大哥與戰爭
阿新 • • 發佈:2017-08-24
namespace 受到攻擊 ng- 發生 ras logs 位置 n-1 接下來
秋實大哥與戰爭
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個士兵所在陣列的長度
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 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\n", r - l - 1); } } } } int main(){ int n, m; while(scanf("%d %d", &n, &m) == 2){ Work(n, m); } }
E - 秋實大哥與戰爭