标签:its color include next turn answer stat eof put
学习set,其他容器每次都要去sort(),除了堆(但其无法lower_bound)
The first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event.
There are three different events described in different format shown below:
D x: The x-th village was destroyed.
Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself.
R: The village destroyed last was rebuilt.
OutputOutput the answer to each of the Army commanders’ request in order on a separate line.
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, c; while (scanf("%d%d", &n, &m) != EOF) { stack<int> sk; set<int> st; st.insert(0), st.insert(n + 1); while (m--) { getchar(); scanf("%c", &c); if (c == ‘R‘) st.erase(sk.top()), sk.pop(); else { scanf("%d", &x); if (c == ‘D‘) st.insert(x), sk.push(x); else if (st.find(x) != st.end()) printf("0\n"); else { auto l = st.lower_bound(x), r = st.lower_bound(x); printf("%d\n", *r - *--l - 1); } } } } return 0; }
标签:its color include next turn answer stat eof put
原文地址:https://www.cnblogs.com/2aptx4869/p/12123684.html