2.9
一
整理一些矩阵相关的思路。(这里的矩阵不是线性代数里的那个,是给一个方阵让你计数或求最优的那种)
1.枚举子矩阵,当然考虑先选出一些可能的情况,然后再考虑优化检查。
2.双指针优化,也算枚举子矩阵的一种吧,就是先枚举两个行,再在这两行为上下界的矩阵中跑双指针。
3.矩阵哈希,上一次碰到还是在海亮打模拟赛,有时前两个想半天没结果可以考虑。
4.上面三个当然可以组合使用。
二
显然我应该把李超线段树的板子再打一遍,但是时间确实不多了。绝对不是我懒
CODE
```plaintext
#include<bits/stdc++.h>
#define auther pair<double,int>
#define fst first
#define sec second
#define usetime() (double)clock () / CLOCKS_PER_SEC * 1000.0
using namespace std;
const int mod1=39989,mod2=1e9+1;
const int maxn=1e5+5;
const double eps=1e-9;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
struct line{
double k,b;
int id;
line(int x1,int y1,int x2,int y2,int idi);
line(){ }
double cal(int x);
};
line::line(int x1,int y1,int x2,int y2,int idi){
id=idi;
if(x1==x2){
k=0,b=max(y1,y2);
return;
}
k=1.0*(y2-y1)/(x2-x1);
b=1.0*y1-1.0*x1*k;
return;
}
int cmp(double a,double b){
if(a-b>eps) return 1;
else if(b-a>eps) return -1;
else return 0;
}
double line::cal(int x){
return k*x+b;
}
int s[mod1<<2];
line p[maxn];
int q,rt=1;
int cnt=0;
int las=0;
void upd(int l,int r,int u,int k){
//cout<<"reporting upd::"<<l<<' '<<r<<' '<<u<<' '<<k<<endl;
//cout<<"upd started!"<<endl;
int &v=s[u];
int mid=(l+r)>>1;
int bmid=cmp(p[k].cal(mid),p[v].cal(mid));
//cout<<"reporting cal::"<<p[k].cal(mid)<<' '<<p[v].cal(mid)<<endl;
//cout<<bmid<<endl;
if(bmid==1||(!bmid&&k<v)) swap(v,k);
int bl=cmp(p[k].cal(l),p[v].cal(l)),br=cmp(p[k].cal(r),p[v].cal(r));
//cout<<k<<' '<<v<<endl;
if(bl==1||(!bl&&k<v)) upd(l,mid,u<<1,k);
if(br==1||(!br&&k<v)) upd(mid+1,r,u<<1|1,k);
//cout<<"upd ended!"<<endl;
return;
}
void update(int L,int R,int id,int l,int r,int u){
if(r<L||l>R) return;
if(r<=R&&l>=L){
upd(l,r,u,id);
return;
}
int mid=(l+r)>>1;
update(L,R,id,l,mid,u<<1),update(L,R,id,mid+1,r,u<<1|1);
return;
}
auther pmax(auther a,auther b){
if(cmp(a.fst,b.fst)==1) return a;
else if(cmp(a.fst,b.fst)==-1) return b;
else return a.sec<b.sec ? a : b;
}
auther query(int l,int r,int u,int d){
if(r<d||l>d) return (auther){0,0};
int mid=(l+r)>>1;
double ans=p[s[u]].cal(d);
if(l==r) return (auther){ans,s[u]};
return pmax((auther){ans,s[u]},pmax(query(l,mid,u<<1,d),query(mid+1,r,u<<1|1,d)));
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int op,x1,y1,x2,y2,k;
read(q);
while(q--){
read(op);
if(op){
read(x1),read(y1),read(x2),read(y2);
x1=(x1+las-1+mod1)%mod1+1,x2=(x2+las-1+mod1)%mod1+1;
y1=(y1+las-1+mod2)%mod2+1,y2=(y2+las-1+mod2)%mod2+1;
if(x1>x2) swap(x1,x2),swap(y1,y2);
++cnt;
p[cnt]=line(x1,y1,x2,y2,cnt);
update(x1,x2,cnt,1,mod1,rt);
}
else{
read(k);
k=(k+las-1+mod1)%mod1+1;
las=query(1,mod1,rt,k).sec;
printf("%d\n",las);
}
}
return 0;
}
来自 2.10 的 huangems: 集训时间不太够,过年再来写,正好可以复习。

浙公网安备 33010602011771号