HDU 5517 Triple (two-dimensional tree-like array)

Source: Internet
Author: User
Tags cas

Title Link: hdu 5517 Triple

Test instructions

There are n two-tuple A, there are M triples B, and set C has a calculation method.

Now let you find the size of set top.

Exercises

After understanding test instructions, it is clear that for each B group, only the largest a can contribute,

You can then find that each element in set B is grouped by E and only corresponds to a, so a maximum of 1e5 triples may contribute.

Then the three-tuple order, with a two-dimensional tree-like array to engage in the line.

1#include <bits/stdc++.h>2 #defineF (I,A,B) for (int i= (a); i<= (b); ++i)3 using namespacestd;4typedefLong Longll;5 6 Const intn=1e5+7;7 intT,n,m,tot,cas,a[n],c[n];8 intc[1007][1007];9 Ten intSumintXinty) One { A     intRET =0; -      for(inti = x;i >0; I-= i&-i) -          for(intj = y;j >0; J-= j&-j) theRET + =C[i][j]; -     returnret; - } - voidAddintXintYintval) + { -      for(inti = X;i <=1003; i + = i&-i) +          for(intj = Y;j <=1003; j + = j&-j) AC[I][J] + =Val; at } -  - intAskintX1,intY1,intX2,inty2) - { -     returnSUM (x2,y2)-sum (x1-1, y2)-sum (x2,y1-1) +sum (x1-1, y1-1); - } in  - structNode to { +     inta,c,d; - ll CNT; theNode (int_a=0,int_c=0,int_d=0, LL _e=0): A (_a), C (_c), D (_d), CNT (_e) {} *     BOOL operator< (ConstNode &AMP;BB)Const $     {Panax Notoginseng         if(A!=BB.A)returna<BB.A; -         if(C!=BB.C)returnc<BB.C; the         returnd<BB.D; +     } A }have[n]; the  +  - intMain () { $scanf"%d",&t); $      while(t--) -     { -F (I,1,100000) a[i]=0; theMemset (c,0,sizeof(c)), tot=0; -scanf"%d%d",&n,&m);Wuyi         inta,b,c; theF (I,1, N) -         { Wuscanf"%d%d",&a,&b); -             if(A>a[b]) a[b]=a,c[b]=0; About             if(A==a[b]) c[b]++; $         } -F (I,1, M) -         { -scanf"%d%d%d",&a,&b,&c); A             if(A[c]) have[++tot]=Node (A[c],a,b,c[c]); +         } theSort (have+1, have+1+tot); -         intTcnt=1; $F (I,2, tot)if(have[i].a==have[tcnt].a&&have[i].c==have[tcnt].c&&have[i].d==have[tcnt].d) the         { thehave[tcnt].cnt+=have[i].cnt; the}Elsehave[++tcnt]=Have[i]; thell ans=0; tot=tcnt; -          for(inti=tot;i;i--) in         { the             if(!ask (HAVE[I].C,HAVE[I].D, +, +)) theans+=have[i].cnt; AboutAdd (HAVE[I].C,HAVE[I].D,1); the         } theprintf"Case #%d:%lld\n",++Cas,ans); the     } +     return 0; -}
View Code

HDU 5517 Triple (two-dimensional 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.