神tm的题
考虑计算总矩形数减没黑点的矩形数
总矩形数等于对行随便选一个子区间的方案数乘以对列随便选一个子区间的方案数,是不是就我这种傻逼写完了程序发现不太会算这个东西-_-
考虑枚举每一行,然后计算每一列上边最多能延伸多少没有黑点,记为h
这样的话我们按列的标号构建一颗treap,并且以h作为堆优先级关键字
因为数据随机所以每个点随机性都是一样的,那么树高就是期望log的
那么每次就相当于整体把h加一,还有单点把h变成0操作
由于每个点都满足儿子的h大于等于自己的h,那么维护答案就比较方便了,具体可看ud函数,不过貌似我写的比较麻烦
#include<iostream>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<bitset>
#include<set>
#include<stack>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 100010
#define MAXM 1010
#define ll long long
#define eps 1e-8
#define MOD 1000000007
#define INF 1000000000
struct pt{
int x;
int y;
friend bool operator <(pt x,pt y){
return x.x<y.x;
}
};
int N,M,n;
pt p[MAXN];
int son[MAXN][2];
ll ch[MAXN],siz[MAXN],v[MAXN],c[MAXN],h[MAXN],vh[MAXN];
int rt;
ll ans;
inline void toch(int x,int y){
if(!x){
return ;
}
ch[x]+=y;
h[x]+=y;
vh[x]+=y*v[x];
}
inline void pd(int x){
if(ch[x]){
toch(son[x][0],ch[x]);
toch(son[x][1],ch[x]);
ch[x]=0;
}
}
inline void ud(int x){
siz[x]=siz[son[x][0]]+siz[son[x][1]]+1;
c[x]=siz[x]+siz[son[x][0]]*siz[son[x][1]];
v[x]=v[son[x][0]]+v[son[x][1]]+c[x];
vh[x]=vh[son[x][0]]+vh[son[x][1]]+c[x]*h[x];
}
void down(int &x,int y){
pd(x);
if(x==y){
h[x]=0;
ud(x);
return ;
}
if(y<x){
down(son[x][0],y);
int t=son[x][0];
if(h[son[x][0]]<h[x]){
son[x][0]=son[t][1];
son[t][1]=x;
ud(x);
x=t;
}
}else{
down(son[x][1],y);
int t=son[x][1];
if(h[son[x][1]]<h[x]){
son[x][1]=son[t][0];
son[t][0]=x;
ud(x);
x=t;
}
}
ud(x);
}
int main(){
int i;
scanf("%d%d%d",&N,&M,&n);
ans=(ll)N*(N+1)/2*M*(M+1)/2;
for(i=1;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p+1,p+n+1);
for(i=1;i<=M;i++){
son[i][0]=i-1;
siz[i]=i;
ud(i);
}
rt=M;
int wzh=1;
for(i=1;i<=N;i++){
toch(rt,1);
while(p[wzh].x==i){
down(rt,p[wzh++].y);
}
ans-=vh[rt];
}
printf("%lld\n",ans);
return 0;
}
/*
5 5 4
1 2
2 3
3 5
4 1
*/