QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317877#4894. 学姐买瓜ushg88770 0ms0kbC++141.3kb2024-01-29 21:04:192024-01-29 21:04:20

Judging History

你现在查看的是最新测评结果

  • [2024-01-29 21:04:20]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-01-29 21:04:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5;
const int sqN=605;
int n,m,le[sqN],ri[sqN],tot,bel[MAXN],to[MAXN],val[MAXN];
int a[MAXN];
void rebuild(int id){
	for(int i=ri[id];i>=le[id];i--){
		if(!a[i]){
			if(i==ri[id]){
				to[i]=i+1;val[i]=0;
			}else to[i]=to[i+1],val[i]=val[i+1];
		}else{
			if(a[i]<ri[id]){
				to[i]=to[a[i]+1];
				val[i]=val[a[i]+1]+1;
			}else{
				to[i]=a[i]+1;
				val[i]=1;
			}
		}
	}
}
void build(){
	int sq=sqrt(n);
	while(ri[tot]!=n){
		le[tot+1]=ri[tot]+1;
		ri[tot+1]=min(n,le[tot+1]+sq);
		++tot;
	}
	for(int i=1;i<=tot;i++) for(int j=le[i];j<=ri[i];j++) bel[j]=i;
	for(int i=1;i<=tot;i++) rebuild(i);
}
int query(int l,int r){
	int ans=0,x=l;
	while(to[x]<=r) ans+=val[x],x=to[x];
	while(x<=r){
		ans+=(a[x]>0&&a[x]<=r);
		x=(a[x]?a[x]+1:x+1);
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(false);
	// freopen("c.in","r",stdin);
	cin>>n>>m;
	build();
	set<int> se;
	for(int i=1;i<=n;i++){
		int o,l,r;cin>>o>>l>>r;
		if(o==1){
			if(!a[l]||a[l]>r){
				a[l]=r;
				rebuild(bel[l]);
				se.insert(l);
				while(se.lower_bound(l)!=se.begin()){
					auto it=--se.lower_bound(l);
					if(a[*it]>=a[l]){
						a[*it]=0;rebuild(bel[*it]);
						se.erase(it);
					}else break;
				}
			}
		}else{
			cout<<query(l,r)<<'\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

11 13
2 4 4
1 11 12
1 1 5
1 2 3
1 2 10
2 2 8
1 6 6
2 2 10
1 6 11
2 2 3
2 2 13

output:

0
1
2
1

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%