题解:
KD树支持矩阵加1,矩阵赋0,查询历史最大值。
时间复杂度 O ( ( m + A ) n + C log n + q n ) O((m+A)\sqrt{n} + C \log n + qn) O((m+A)n+Clogn+qn)。
代码标记用了二元组,没把常数压下去。。
#include <bits/stdc++.h>
using namespace std;
const int RLEN=1<<18|1;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
char ch=nc(); int i=0,f=1;
while(!isdigit(ch)) {
if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {
i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
return i*f;
}
inline void W(int x) {
static int buf[50];
if(!x) {
putchar('0'); return;}
if(x<0) {
putchar('-'); x=-x;}
while(x) {
buf[++buf[0]]=x%10; x/=10;}
while(buf[0]) {
putchar(buf[buf[0]--]+'0');}
}
const int N=5e4+50, INF=0x3f3f3f3f;
int n,m,q,tot;
inline int Max(int x,int y) {
return (x>y) ? x : y;}
inline int Min(int x,int y) {
return (x<y)