标签:des style blog http color os io ar for
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 1000000000 13 #define maxn 100000+1000 14 #define maxm 500+100 15 #define eps 1e-10 16 #define ll long long 17 #define pa pair<int,int> 18 using namespace std; 19 inline int read() 20 { 21 int x=0,f=1;char ch=getchar(); 22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 24 return x*f; 25 } 26 struct edge{int go,next;}e[2*maxn]; 27 int n,tot,ti,s[2*maxn],l[maxn],r[maxn],head[maxn]; 28 bool v[maxn]; 29 void insert(int x,int y) 30 { 31 e[++tot].go=y;e[tot].next=head[x];head[x]=tot; 32 e[++tot].go=x;e[tot].next=head[y];head[y]=tot; 33 } 34 void dfs(int x) 35 { 36 v[x]=1; 37 l[x]=++ti; 38 for(int i=head[x],y;i;i=e[i].next) 39 if(!v[y=e[i].go])dfs(y); 40 r[x]=++ti; 41 } 42 void add(int x,int y) 43 { 44 for(;x<=2*n;x+=x&(-x))s[x]+=y; 45 } 46 int sum(int x) 47 { 48 int t=0; 49 for(;x;x-=x&(-x))t+=s[x]; 50 return t; 51 } 52 int main() 53 { 54 freopen("input.txt","r",stdin); 55 freopen("output.txt","w",stdout); 56 n=read(); 57 int x,y; 58 for(int i=1;i<n;i++)x=read(),y=read(),insert(x,y); 59 dfs(1); 60 for(int i=1;i<=n;i++) 61 { 62 int x=read(); 63 printf("%d\n",sum(l[x])); 64 add(l[x],1);add(r[x],-1); 65 } 66 return 0; 67 }
BZOJ1782: [Usaco2010 Feb]slowdown 慢慢游
标签:des style blog http color os io ar for
原文地址:http://www.cnblogs.com/zyfzyf/p/3941400.html