"discretized Tree Array" Nordic Collegiate programming Contest g.galactic Collegiate Programming Contest

Source: Internet
Author: User

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 intn,m;5 Const intmaxn=1e5+3;6 structnode7 {8     intteam;9     intnum;Ten     intTime ; One     intID; A }A[MAXN]; - intANS[MAXN]; - intB[MAXN]; the intC[MAXN]; - intS[MAXN]; - intTEAM[MAXN]; - intTREE[MAXN]; + intPRE[MAXN]; - intLowbit (intx) + { A     returnx& (-x); at } - voidAddintKintx) - { -      while(k<=m) -     { -tree[k]+=x; ink+=Lowbit (k);  -     } to } + intQueryintk) - { the     intres=0; *      while(k) $     {Panax Notoginsengres+=Tree[k]; -k-=Lowbit (k); the     } +     returnRes; A } the  + BOOLCMP (node X,node y) - { $     if(X.num!=y.num)returnX.num>Y.num; $     Else if(X.time!=y.time)returnx.time<Y.time; -     Else if(x.team!=1)return false; -     //else return true; the } - intMain ()Wuyi { the      while(~SCANF ("%d%d",&n,&m)) -     { Wumemset (b,0,sizeof(b));//Number of questions -Memset (c,0,sizeof(c));//penalty Hours Aboutmemset (Tree,0,sizeof(tree)); $memset (ans,0,sizeof(ans)); -memset (PRE,0,sizeof(pre)); -         inttmp; -          for(intI=1; i<=m;i++) A         { +scanf"%d%d",&a[i].team,&tmp); thea[i].num=b[a[i].team]+1; -b[a[i].team]=A[i].num; $a[i].time=c[a[i].team]+tmp; thec[a[i].team]=A[i].time; theA[i].id=i; theteam[i]=A[i].team; the         } -Sort (A +1, A +1+m,cmp); in          for(intI=1; i<=m;i++) the         { thes[a[i].id]=i; About         } the          for(intI=1; i<=m;i++) pre[team[i]]=-1; the         intR=m; the          for(intI=1; i<=m;i++) +         { -             if(pre[team[i]]!=-1) theAdd (pre[team[i]],-1);Bayipre[team[i]]=S[i]; the             if(team[i]==1) ther=s[i]-1; -Add (S[i],1); -Ans[i]=query (R) +1; the         }     the          for(intI=1; i<=m;i++) cout<<ans[i]<<Endl; the              the     } -     return 0; the}
View Code

Note that the custom CMP, and finally no return causes WA

http://codeforces.com/gym/101572/attachments/download/6091/20172018- Acmicpc-nordic-collegiate-programming-contest-ncpc-2017-en.pdf

"discretized Tree Array" Nordic Collegiate programming Contest g.galactic Collegiate Programming Contest

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.