June 21 BC Summary

Source: Internet
Author: User

June 21 BC Summary

Recently BC due to the rush to submit, increased the probability of WA, today 1001 data is not fully submitted, WA once, very not cost-effective, in BC equals penalty 10min, next time must ensure that the data is correct and all the circumstances are considered to resubmit.

1001

Water problem, 5 minutes WA was once, 6 minutes too. Hand speed or slow, the focus is actually WA once.

1002

Given an array, ask multiple times the number of reverse in the L and R intervals.

The array size is less than 1000.

The violence FST.

Idea: Set DP (L,R) to the inverse number of the interval L to R. DP (L,R) =DP (l,r-1) +cnt (l,r), where CNT (L,R) represents the contribution of A[r] to DP (L,R), which is the number of large numbers in the interval [l,r-1] greater than a[r.

The DP (L,R) can be obtained by the direct n^2 pretreatment after the CNT is obtained.

Now the question is how to find CNT (L,R).

The simple approach is to n^3 violence directly, apparently not.

It can be considered that the contribution of the interval [l,r],a[r] to the interval is CNT (L,R), that is, the number of larger numbers in [l,r-1] than a[r], whereas CNT (L+1,R) represents the number of larger numbers than l+1,r-1 in [a[r], whereas CNT (L+1,R) and CNT (l , R) What is the difference between, yes, the difference is (A[l],a[r]) The number of reverse order.

Therefore, CNT (L,R) =cnt (l+1,r) + (A[l]>a[r]). N^2 pretreatment can be, because CNT (L+1,R) than CNT (L,R) is calculated first, so to reverse the push.

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<vector>#include<stack>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<cctype>#definell Long Long#defineREP (I,A,B) for (int (i) = (a);(i) <= (b);(i) + +)#defineRepp (i,a,b,t) for (int (i) = (a);(i) <= (b);(i) + = (t))#defineRep (i,a,b) for (int (i) = (a);(i) >= (b);(i)--)#defineRepp (i,a,b,t) for (int (i) = (a);(i) >= (b);(i)-= (t))#definePII pair<int,int>#defineFST First#defineSND second#defineMP Make_pair#definePB push_back#defineRI (x) scanf ("%d",& (x))#defineRII (x, y) scanf ("%d%d",& (×),& (y))#defineRIII (x, Y, z) scanf ("%d%d%d",& (×),& (y),& (z))#defineDRI (x) int (x); scanf ("%d",& (x))#defineDrii (x, y), scanf ("%d%d",& (x),& (y))#defineDRIII (x, y), (z), scanf ("%d%d",& (x),& (y),& (z))#defineRS (x) scanf ("%s", s)#defineRSS (x, y) scanf ("%s%s", X, y)#defineDRS (x) char x[maxn];scanf ("%s", X)#defineDrss (x, y) char x[maxn],y[maxn];scanf ("%s%s", X, y)#defineMS0 (a) memset ((a), 0,sizeof ((a)))#defineMS1 (a) memset ((a), -1,sizeof ((a)))#defineMS (b) memset ((a), (b), sizeof ((a)))#defineAll (v) v.begin (), V.end ()#defineSZ (v) (v). Size ()using namespacestd;Const intmaxn=1100;Const intInf= (1<< in);Const Doubleeps=0.0000000001;Const DoublePi=acos (-1.0);intn,q;intA[MAXN];intF[MAXN][MAXN],CNT[MAXN][MAXN];intMain () { while(cin>>n>>q)        {MS0 (f);        MS0 (CNT); REP (i,1, N)        RI (A[i]); Rep (I,n,1) {Rep (j,n,i) {Cnt[i][j]=cnt[i+1][j]+ (a[i]>A[j]); }} REP (I,1, N) {REP (j,i,n) {F[i][j]=f[i][j-1]+Cnt[i][j]; }        }         while(q--) {drii (l,r); printf ("%d\n", F[l][r]); }    }    return 0;}
View Code

This problem with a tree-like array can also, the advantage of data structure is to reduce the amount of thinking, increase the stability of the problem, many people in the first few tonight is the second write tree array. It seems that a tree-like array is a useful tool, so be sure to learn it well.

June 21 BC Summary

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.