HDU---4417Super Mario tree-like array for offline operation

Source: Internet
Author: User

Test instructions: Given n number, the query position L R is less than the number of x in how many.

For a query to add all the "position" of the number smaller than x to the tree array, then sum (R)-sum (L-1) is the answer, Q query will be done offline, sorted by height.

#include <Set>#include<map>#include<cmath>#include<ctime>#include<queue>#include<stack>#include<cctype>#include<cstdio>#include<string>#include<vector>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;typedef unsignedLong LongUll;typedefLong Longll;Const intINF =0x3f3f3f3f;Const DoubleEPS = 1e-8; template<classT>inlineBOOLScan_d (T &ret) {    CharC; intSGN; if(C=getchar (), c==EOF)return 0;  while(c!='-'&& (c<'0'|| C>'9')) c=GetChar (); SGN= (c=='-')?-1:1; RET= (c=='-')?0:(C-'0');  while(C=getchar (), c>='0'&&c<='9') ret=ret*Ten+ (C-'0'); RET*=SGN; return 1;}Const intMAXN = 1e5+ -;intN,Q,C[MAXN];intLowbit (intx) {    returnX &-x;}voidAddintXintBD) {     while(x <=N) {c[x]+=D; X+=lowbit (x); }}intSumintx) {    intAns =0;  while(X >0) {ans+=C[x]; X-=lowbit (x); }    returnans;}structnode1{intV,index;} H[MAXN];structnode2{intL,r,v,index,ans;} H[MAXN];BOOLCMP1 (ConstNode1 &n1,ConstNode1 &n2) {    returnN1.V <n2.v;}BOOLCMP2 (ConstNode2 &n1,ConstNode2 &n2) {    returnN1.V <n2.v;}BOOLCmp3 (ConstNode2 &n1,ConstNode2 &n2) {    returnN1.index <N2.index;}intMainvoid) {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    intT,cas =1; scanf ("%d",&t);  while(t--) {memset (c,0,sizeof(c)); scanf ("%d%d",&n,&q);  for(inti =1; I <= N; i++) {scanf ("%d",&h[i].v); H[i].index=i; } sort (H+1, h+n+1, CMP1);  for(inti =1; I <= Q; i++) {scanf ("%d%d%d",&h[i].l,&h[i].r,&h[i].v); H[I].L++; H[I].R++; H[i].index=i; } sort (H+1, h+q+1, CMP2); intj =1;  for(inti =1; I <= Q; i++)        {            intTMP =h[i].v;  while(H[J].V <= tmp&&j<=n)//We're going to add j<=n, or we'll die loops .{Add (H[j].index,1); J++; } H[i].ans= SUM (H[I].R)-SUM (h[i].l-1); } sort (H+1, h+q+1, Cmp3); printf ("Case %d:\n", cas++);  for(inti =1; I <= Q; i++) {printf ("%d\n", H[i].ans); }    }    return 0;}
View Code

HDU---4417Super Mario tree-like array for offline operation

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.