求助NOIP2023T4卡常
  • 板块题目总版
  • 楼主_XHY20180718_
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/11/26 23:01
  • 上次更新2023/11/27 14:23:32
查看原帖
求助NOIP2023T4卡常
399475
_XHY20180718_楼主2023/11/26 23:01

非递归函数都展开了,线段树连建树都没写,常数到底哪里大了?

#include<bits/stdc++.h>
#define int long long
#define mid (l+(r-l>>1))
#define max(x,y) (x>y?x:y)
#define ls (mid<<1)
#define rs (mid<<1|1)
using namespace std;
const int N=4e5+5,inf=1e9;
int c,t,n,m,k,d,ans;
int b[N],L,R,K;
struct node{
	int l,r,w;
	bool operator<(const node &t)
	const{return r<t.r;}
}nd[N>>2];
struct Tree{int w,fl;}tr[N<<1];
void upd(int l,int r,int id){
	if(L<=l&&r<=R){tr[id].w+=K,tr[id].fl+=K;return;}
	int x=tr[id].fl;if(x){
	    tr[ls].w+=x,tr[ls].fl+=x;
	    tr[rs].w+=x,tr[rs].fl+=x;
	    tr[id].fl=0;}
	if(L<=mid)upd(l,mid,ls);
	if(mid<R)upd(mid+1,r,rs);
	tr[id].w=max(tr[ls].w,tr[rs].w);
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>c>>t;while(t--){
		cin>>n>>m>>k>>d;n=0;
		for(int i=1; i<=m; ++i)
			cin>>nd[i].r>>nd[i].l>>nd[i].w,
			nd[i].l=nd[i].r-nd[i].l+1,
			b[++n]=nd[i].l,b[++n]=nd[i].r;
		for(int i=1,t=n; i<=t; ++i)b[++n]=b[i]+1;
		sort(b+1,b+1+n);n=unique(b+1,b+1+n)-b-1;
		for(int i=1; i<=m; ++i)
			nd[i].l=lower_bound(b+1,b+1+n,nd[i].l)-b,
			nd[i].r=lower_bound(b+1,b+1+n,nd[i].r)-b;
        sort(nd+1,nd+1+m);
		for(int i=1,t; i<=m; ++i){
			t=lower_bound(b+1,b+1+n,b[nd[i].r]-k+1)-b;
			for(int j=max(nd[i-1].r+1,t); j<=nd[i].r; ++j){
				L=t,R=j-1,K=-d*(b[j]-b[j-1]);if(L<=R)upd(1,n,1);
				L=R=j,K=-d,upd(1,n,1);ans=max(ans,tr[1].w);
			}
			L=t,R=nd[i].l,K=nd[i].w;if(L<=R)upd(1,n,1);
            ans=max(ans,tr[1].w);
			for(int j=nd[i].r+1; j<=nd[i+1].r; ++j)
			{L=R=j+1,K=max(tr[1].w,0ll);if(R<=n)upd(1,n,1);}
		}cout<<ans<<'\n';ans=0;++n;
		memset(tr,0,sizeof*tr*n<<1);
	}
    return 0;
}
2023/11/26 23:01
加载中...