"Hdu 5517" "2015ACM/ICPC Asia Shenyang Station" Triple test Instructions & Code (c + +)

Source: Internet
Author: User

Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=5517
Test Instructions:
Given n two-tuple <a,b> and M-triples <c,d,e> now combine it into a new ternary set, with duplicate elements allowed in the new ternary group, a two-tuple and a ternary group that can be combined when and only when B==e is combined into <a,c,d> Any element <a,b,c> in the new group of triples, if there is an element in the new combination <u,v,w> makes U!=a && v!=b && w!=c u>=a && V >=b &&w>=c element <a,b,c> does not count in the collection of answers, otherwise it is counted in the collection of answers, asking how many elements are in the collection of final answers, and can have repeating elements.
The following:
There are three-dimensional information, we found that the value of a in the new ternary group in the 10^5 range, and the B,c range is within 1000, so you can use a to sort, and then use B,C statistics in a two-dimensional tree array, in the composition of the new triples there are also some techniques and methods, you can refer to the code to understand.
The subject to use a long long, multiple sets of data attention to initialization.
Code:

#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>using namespace STD;intT,n,m;intid[100005];Long Longcnt[100005];structnode{intAintbintCLong LongNum;} p[100005],np[100005];Long Longsum[1005][1005];intCMP (node X1,node x2) {if(x1.a!=x2.a)returnx1.a<x2.a;if(x1.b!=x2.b)returnx1.b<x2.b;returnx1.c<x2.c; }intPaninti) {if(p[i].a==p[i+1].a&&p[i].b==p[i+1].b&&p[i].c==p[i+1].C)return 1;return 0;}intLowbit (intx) {returnx& (-X);}intAddintXintYLong LongV) { for(inti=x;i<= +; I+=lowbit (i)) for(intj=y;j<= +; J+=lowbit (j)) Sum[i][j]+=v; }Long LongQueryintXintY) {Long Longres=0; for(inti=x;i>=1; I-=lowbit (i)) for(intj=y;j>=1; J-=lowbit (j)) Res+=sum[i][j];returnRes;}intSolveintXintY) {Long LongRes=query ( +, +)-query (x1, +)-query ( +, Y1) +query (x1, Y1);if(res==0)return 1;Else    return 0;}intMain () {scanf("%d", &t); for(intt=1; t<=t;t++) {scanf("%d%d", &n,&m);memset(Sum,0,sizeof(sum));memset(ID,0,sizeof(ID));memset(CNT,0,sizeof(CNT)); for(intI=1; i<=n;i++) {intb;scanf("%d%d", &a,&b);if(Id[b]<a)                {id[b]=a; cnt[b]=1; }Else if(id[b]==a) cnt[b]++; }inttot=0; for(intI=1; i<=m;i++) {intA,b,c;scanf("%d%d%d", &a,&b,&c);if(id[c]!=0) {tot++;                P[TOT].A=ID[C];                P[tot].b=a;                P[tot].c=b;            P[TOT].NUM=CNT[C]; }} sort (p+1, p+1+TOT,CMP);intnn=0;Long Longres=0; for(intI=1; i<=tot;i++) {if(Pan (i)) res+=p[i].num;Else{nn++; np[nn].num=0;                Np[nn]=p[i];                Np[nn].num+=res; res=0; }        }Long Longans=0; for(inti=nn;i>=1; i--) {if(Solve (NP[I].B,NP[I].C)) Ans+=np[i].num;        Add (Np[i].b,np[i].c,np[i].num); }printf("Case #%d:%i64d\n", T,ans); }}

"Hdu 5517" "2015ACM/ICPC Asia Shenyang Station" Triple test Instructions & Code (c + +)

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.