HDU 5273 Dylans loves sequence "tree-like array"

Source: Internet
Author: User

Test instructions: Give the number of N, and then give Q a query, to find the number of reverse order L to R

Write your own time, is each inquiry is re-inserted to find sum (r)-sum (L)

Decisive T

Later, I saw someone else's code----

Pre-processing, ask all possible intervals (1000*1000), then ask O (1)

And then want to write this time out, because there are too many inquiries----

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=1005; -  - intA[MAXN]; + intC[MAXN];//tree-like array - intn,m; + intANS[MAXN][MAXN]; A  at structnode{ -     intX,id; - }P[MAXN]; -  - intCMP (node N1,node n2) { -     returnn1.x <n2.x; in } -  to intLowbit (intx) {returnX & (-x);} +  - intSumintx) { the     intret=0; *      while(x>0){  $RET + = c[x];x-=lowbit (x);Panax Notoginseng     } -     returnret; the } +  A voidAddintXintd) { the      while(x<=N) { +c[x]+=d;x+=lowbit (x); -     } $ } $  - intMain () { -      while(SCANF ("%d%d", &n,&m)! =EOF) { theMemset (c,0,sizeof(c)); -Memset (A,0,sizeof(a));Wuyimemset (ans,0,sizeof(ans)); the          for(intI=1; i<=n;i++) { -scanf"%d",&p[i].x); WuP[i].id=i; -         } AboutSort (p+1, p+n+1, CMP); $          for(intI=1, j=0; i<=n;i++){ -             if(i==1|| P[i].x! = p[i-1].x) J + +; -a[p[i].id]=J; -         } A          +     //for (int i=1;i<=n;i++) the     //printf ("a[%d]=%d\n", I,a[i]); -          $          for(intI=1; i<=n;i++){ theMemset (c,0,sizeof(c)); the             intres=0; the              for(intj=i;j<=n;j++){ theres+= (J-i)-sum (a[j]); -Add (A[j],1); inANS[I][J] =Res; the             } the         } About      the          while(m--){ the             intL,r; thescanf"%d%d",&l,&R); +printf"%d\n", Ans[l][r]); -         } the     } Bayi     return 0; the}
View Code

HDU 5273 Dylans loves sequence "tree-like array"

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.