Metropolitan Meg bzoj-1103 POI-2007
Topic : Given a tree of n points, M operations. Change the Benquan of a path to 0 and query a point to the root node for point weights and. The Benquan at the beginning of all sides were 1.
Note : $1\le n,m\le 2.5\cdot 10^5$.
idea : We pull out the DFS sequence first. In fact, strictly speaking is the stack into the stack, that is, each point in the order of two occurrences of that.
At the beginning of the stack when the point right is 1, the stack is-1. The modification is to change the stack into 0. Then query the prefix with a tree-like array.
finally , attach the ugly code ...
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define N 250010 Using namespace Std;int tree[n<<1],val[n<<1],head[n],to[n<<1],nxt[n<<1],tot,cnt;int Dic[N <<1];struct node{int x, y;} a[n];inline int lowbit (int x) {return x& (-X);} void fix (int x,int delta) {for (int i=x;i<=cnt+1;i+=lowbit (i)) {//puts ("fix"); Tree[i]+=delta;}} int query (int x) {int ans=0;for (int i=x;i>=1;i-=lowbit (i)) {//puts ("query"); ans+=tree[i];} return ans;} inline void Add (int x,int y) {to[++tot]=y;nxt[tot]=head[x];head[x]=tot;} void Dfs (int pos,int fa) {//if (a[pos].x) puts ("Fuck");d ic[++cnt]=pos;//cnt++;val[cnt]=1;a[pos].x=cnt;for (int i=head[ Pos];i;i=nxt[i]) {if (TO[I]==FA) Continue;dfs (To[i],pos);} dic[++cnt]=pos;//cnt++;val[cnt]=-1;a[pos].y=cnt;} int main () {int n; cin >> n; int x,y;for (int i=1;i<n;i++) {scanf ("%d%d", &x,&y); Add (x, y); add (y,x);} DFS (1,0); val[1]=0;val[cnt]=0;for (int i=1;i<=cnt;i++) {fix (i,val[i]);} printf ("Gun%d\n ", CNT);//for (int i=1;i<=cnt;i++)//{//printf (" Shit%d\n ", dic[i]);//}//puts ("--------------------------- -----------"); int m; Cin >> m; Char opt[10];//for (int. i=1;i<=n;i++) printf ("%d%d\n", a[i].x,a[i].y); for (int i=1;i<=n+m-1;i++) {/ /printf ("Fuck%d\n", i), scanf ("%s", opt+1), if (opt[1]== ' A ') {scanf ("%d%d", &x,&y), if (x>y) swap (x, y); Fix (a[ Y].X,-1); fix (a[y].y,1);} ELSE{SCANF ("%d", &x);//printf ("%d\n", Query (3));p rintf ("%d\n", Query (a[x].x));}} return 0;}
Summary : simple questions.
[bzoj1103] [POI2007] Metropolitan Meg_dfs Sequence _ tree-like array