AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3289
【题解】
用树状数组维护逆序对,然后对于询问用莫队就行了,这题还得离散化来搞。
/*************
bzoj 3289
by chty
2016.11.17
*************/
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
#define FILE "read"
#define MAXN 50010
#define up(i,j,n) for(ll i=j;i<=n;i++)
struct node{ll x,y,id;}q[MAXN];
ll n,m,now,tot,block,a[MAXN],ans[MAXN];
pairb[MAXN];
namespace Init{
char buf[1<<15],*fs,*ft;
inline char getc() {return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;}
inline ll read(){
ll x=0,f=1; char ch=getc();
while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getc();}
while(isdigit(ch)) {x=x*10+ch-'0'; ch=getc();}
return x*f;
}
}
namespace Tree_Array{
ll c[MAXN];
ll lowbit(ll x) {return x&(-x);}
void updata(ll x,ll v){for(ll i=x;i<=tot;i+=lowbit(i)) c[i]+=v;}
ll query(ll x){ll sum=0;for(ll i=x;i;i-=lowbit(i)) sum+=c[i]; return sum;}
}
namespace Mo_Team{
bool cmp(node a,node b) {return (a.x/block==b.x/block)?a.yr) now+=Tree_Array::query(tot)-Tree_Array::query(a[++r]),Tree_Array::updata(a[r],1);
while(q[i].yl) Tree_Array::updata(a[l],-1),now-=Tree_Array::query(a[l++]-1);
while(q[i].x