HDU 5147 bestcoder #23 (tree array interval prefix and, suffix, and) are similar to LA4329

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.