标签:nyoj 树状数组
链接:click here
题意:
2
3
1 2 3
4
4 3 2 1
0
6
代码:
#include <math.h> #include <queue> #include <deque> #include <vector> #include <stack> #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> using namespace std; #define lowbit(a) a&-a #define Max(a,b) a>b?a:b #define Min(a,b) a>b?b:a #define mem(a,b) memset(a,b,sizeof(a)) int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}}; const double eps = 1e-6; const double Pi = acos(-1.0); static const int inf= ~0U>>2; static const int maxn =110; int h[1000001],w[100],Map[200]; int m[10001], N; void Add(int i) { while(i<=1001) { m[i]++; i+=lowbit(i); } } int Sum(int i) { int res=0; while(i>0) { res+=m[i]; i-=lowbit(i); } return res; } int main() { int T,temp; scanf("%d",&T); while(T--) { scanf("%d",&N); memset(m,0,sizeof(m)); int ans=0; for(int i=1; i<=N; i++) { scanf("%d",&temp); Add(temp); ans+=(i-Sum(temp)); } printf("%d\n",ans); } return 0; }When you want to give up, think of why you persist until now!
NYOJ 233 &&NYOJ 322 Sort(树状数组)
标签:nyoj 树状数组
原文地址:http://blog.csdn.net/u013050857/article/details/43939917