社区讨论
把#5下载了本地能过但WA70
P4097【模板】李超线段树 / [HEOI2013] Segment参与者 4已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 10 条
- 当前快照
- 1 份
- 快照标识符
- @mdfsiu7b
- 此快照首次捕获于
- 2025/07/23 17:58 7 个月前
- 此快照最后确认于
- 2025/11/04 03:52 4 个月前
CPP
#include<bits/stdc++.h>
#define int long long
#define double long double
#define R(x) x=read()
using namespace std;
inline int read() {
int x=0,y=1;
char e=getchar();
while(e<'0'||e>'9') {
if(e=='-')y=-1;
e=getchar();
}
while(e>='0'&&e<='9') {
x=(x<<1)+(x<<3)+(e^'0');
e=getchar();
}
return x*y;
}
int n;
int s[40005<<2];
#define lo (nw<<1)
#define ro (nw<<1|1)
#define md ((l+r)>>1)
struct node {
int id;
double k,b;
} lines[100005];
int cnt;
int cmp(double A,double B) {
if(A-B>1e-19)return 1;
if(B-A>1e-19)return -1;
return 0;
}
int calc(int id,int x) {
return lines[id].k*x+lines[id].b;
}
void update(int nw,int l,int r,int f) {
int &g=s[nw],res;
res=cmp(calc(f,md),calc(g,md));
if(res==1||(res==0&&f<g)) swap(f,g);
res=cmp(calc(f,l),calc(g,l));
if(res==1||(res==0&&f<g)) update(lo,l,md,f);
res=cmp(calc(f,r),calc(g,r));
if(res==1||(res==0&&f<g)) update(ro,md+1,r,f);
}
void add(int nw,int l,int r,int x,int y,int k) {
if(x<=l&&r<=y) {
update(nw,l,r,k);
return ;
}
if(x<=md)add(lo,l,md,x,y,k);
if(y>md)add(ro,md+1,r,x,y,k);
}
pair<double,int>mx(pair<double,int>A,pair<double,int>B) {
if(cmp(A.first,B.first)==1)return A;
if(cmp(A.first,B.first)==-1)return B;
return A.second<B.second?A:B;
}
pair<double,int> ask(int nw,int l,int r,int x) {
if(l>x||r<x) return {0,0};
double res=calc(s[nw],x);
if(l==r)return {res,s[nw]};
return mx({res,s[nw]},mx(ask(lo,l,md,x),ask(ro,md+1,r,x)));
}
signed main() {
R(n);
int lstans=0;
for(int i=1; i<=n; ++i) {
int R(op);
if(!op) {
int R(k);
k=(k+lstans-1)%39989+1;
lstans=ask(1,1,40000,k).second;
cout<<lstans<<"\n";
} else {
int R(x),R(y),R(xx),R(yy);
x=(x+lstans-1)%39989+1;
xx=(xx+lstans-1)%39989+1;
y=(y+lstans-1)%1000000000+1;
yy=(yy+lstans-1)%1000000000+1;
if(x>xx){
swap(x,xx),swap(y,yy);
}
++cnt;
lines[cnt].id=cnt;
if(x==xx) {
lines[cnt].k=0,lines[cnt].b=max(y,yy);
} else {
lines[cnt].k=(y-yy)*1.0/(x-xx);
lines[cnt].b=y-lines[cnt].k*x;
}
add(1,1,40000,x,xx,cnt);
}
}
return 0;
}
#5:
CPPin:
3
1 8 7 3 9
1 10 9 4 3
0 8
out:
1
回复
共 11 条回复,欢迎继续交流。
正在加载回复...