[Codeforces] 877E. Danil and a Part-time Job
題目連結: http://codeforces.com/problemset/problem/877/E 把樹壓扁後題目就轉化成有一個01序列,並且有兩種操作:查詢區間和跟把區間的bit反轉。稍微想一下會發現線段樹可以好好做他,所以就用線段樹維護一下就好了。 #include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef pair<int,bool> PIB;
#define FF first
#define SS second
const int N = 200000 + 5;
class SegTree{
private:
PIB nodes[N<<2];
int n;
inline int lc(int x){return 2*x+1;}
inline int rc(int x){return 2*x+2;}
inline void push(int l, int r, int id){
if(!nodes[id].SS) return;
nodes[id].FF = r-l - nodes[id].FF;
if(r-l > 1){
nodes[lc(id)].SS ^= nodes[id].SS;
nodes[rc(id)].SS ^= nodes[id].SS;
}
nodes[id].SS = 0;
}
inline void pull(int l, int r, int id){
int val = 0, mid = (l+r)>>1;
if(nodes[lc(id)]...