General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
200063148 Practice:
chappy1
780G - 17 C++17 (GCC 7-32) Accepted 436 ms 105308 KB 2023-04-01 05:05:25 2023-04-01 05:05:36
→ Source
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define F first
#define S second
#define lc (2*id)
#define rc (2*id+1)
#define md ((s+e)/2)
#define ln (e-s+1)
#define mk make_pair
typedef long long ll;

const int N=1e6+7,mod=1e9+7;
ll w,t[N],h[N],z,u[N],L[N],R[N],S[N];
vector<int>seg[N];
pair<int,int>p[N];

void add(int x,int k,int id=1,int s=1,int e=w){
	seg[id].pb(k);
	if(ln==1) return;
	if(md>=x)add(x,k,lc,s,md);
	else add(x,k,rc,md+1,e);
}

ll upd(int l,int r,int x,int id=1,int s=1,int e=w){
	if(l>e || s>r) return 0;
	if(s>=l && e<=r){
		ll s=0;
		while(seg[id].size() && h[seg[id].back()]<=x){
			s+=t[seg[id].back()];
			s%=mod;
			t[seg[id].back()]=0;
			seg[id].pop_back();
		}		
		return s;
	}
	return (upd(l,r,x,lc,s,md)+upd(l,r,x,rc,md+1,e))%mod;
}


int main(){
	ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int H,n;
	cin>>H>>w>>n;
	for(int i=1;i<=w;i++){
		t[z]=1;h[z]=H+1;
		add(i,z);z++;
	}
	for(int i=0;i<n;i++){
		cin>>u[i]>>L[i]>>R[i]>>S[i];
		//S[i]--;
		p[i]=mk(u[i],i);
	}
	sort(p,p+n,greater<pair<int,int>>());
	for(int j=0;j<n;j++){
		int i=p[j].S;
		int x=upd(L[i],R[i],u[i]+S[i]);
		if(R[i]!=w){
			t[z]=(x+(L[i]==1)*x)%mod;
			h[z]=u[i];
			add(R[i]+1,z);z++;
		}
		if(L[i]!=1){
			t[z]=(x+(R[i]==w)*x)%mod;
			h[z]=u[i];
			add(L[i]-1,z);z++;
		}
	}
	ll ans=0;
	for(auto q:seg[1]){
		ans+=t[q];
		ans%=mod;
	}
	cout<<ans<<endl;
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details