The two logarithmic intermediate intersections should be freely available. If a logarithm is included, the logarithm should be selected first.
Read in order, throw in a log, discard the tree-like array and update the effect on other locations.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 Const intmaxn=50023;7 intt[maxn<<1],PRE[MAXN];8 intI,j,k,n,m,ans;9 TenInlinevoidDelintx) { while(x<=n) t[x]--, x+=x&-x;} OneInlinevoidAddintx) { while(x<=n) t[x]++,x+=x&-x;} AInlineint Get(intx) {intsm=0; while(x) sm+=t[x],x-=x&-x;returnSM;} - intRaCharRx; -InlineintRead () { theRx=getchar (), ra=0; - while(rx<'0'|| Rx>'9') rx=GetChar (); - while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } + intMain () { -N=read () <<1; + for(i=1; i<=n;i++){ Aj=read (); at if(!pre[j]) pre[j]=i,add (i);Else -ans+=Get(i)-Get(pre[j]-1)-1, - del (pre[j]); - } -printf"%d\n", ans); -}
View Code
[bzoj1106] [POI2007] cube big battle tet