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