Similar LA4329
1..N numbers are placed in n lattices, and the four-tuple satisfies (a,b,c,d) a<b<c<d and Aa<ab,ac<ad. The number of.
This problem just started to know to use a tree array to do, at first think of the enumeration a,c such words of complexity n^2 inevitable tle and a,c between the numbers greater than a can not be counted.
The puzzle: Enumerate C points.
And then get c before satisfying the number of a, a, and then multiply the number of D larger than C is the number of enumeration C at this time. Here is the technique of a sub-problem, when enumerating C to I, I-1 is known to store a quantity that satisfies A, b at i-1
Then, when I time, the value of a and B is added to the number of smaller i-1.
Careful overflow.
/* ***********************************************author:bingonecreated TIME:2014/12/20 18:56:36File name:b estcoder23.cpp************************************************ * * #include <stdio.h> #include <string.h > #include <iostream> #include <algorithm> #include <vector> #include <queue> #include < set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include < Time.h> #define INF 0x3f3f3f3f#define MAXN (10+60000) #define LOWBIT (x) (X&-x) using namespace Std;typedef long lon G Ll;int n,m,t;int se[maxn];int getsum (int x) {int Res=0;while (x>0) {res+=se[x];x-=lowbit (x);} return res;} void Add (int x) {while (x<=n) {se[x]++;x+=lowbit (x);}} int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), scanf ("%d", &t), while (t--) {memset (se,0,sizeof (SE)); scanf ("%d", &n); ll ans =0,pre=0;for (int i=1;i<=n;i++) {int m;scanf ("%d", &m); int t=getsum (m); int k=n-m-(I-T-1);//Behind S[i] Large number Ans+=k*pre;pre+=t;add (m);} printf ("%i64d\n", ans);} return 0;}
HDU 5147 bestcoder #23 (tree array interval prefix and, suffix, and) are similar to LA4329