QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400537#4894. 学姐买瓜OIer20080 0ms0kbC++141.9kb2024-04-27 13:27:352024-04-27 13:27:35

Judging History

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

  • [2024-04-27 13:27:35]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-04-27 13:27:35]
  • 提交

answer

#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define V inline void
#define I inline int
#define vi vector<int>
#define pi pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
const int N=3e5+10;
I read() {
	int x=0,y=1;char c=getchar();
	while(c<48||c>57){if(c==45)y=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*y;
}
pi a[N];
int n,m,B,f[N],f2[N],g[N],g2[N],s[N],s2[N],L[N],R[N],bel[N];
I F(int x) {
	return f2[bel[x]]?f2[bel[x]]:f[x]; 
}
I G(int x) {
	return g2[bel[x]]?g2[bel[x]]:g[x];
}
I S(int x) {
	return g2[bel[x]]?s2[bel[x]]:s[x];
}
V rebuild(int x) {
	f2[x]=g2[x]=s2[x]=0;
	fd(i,R[x],L[x]) {
		if(f[i]>R[x]) g[i]=f[i],s[i]=1;
		else g[i]=g[f[i]],s[i]=s[f[i]]+1;
	}
}
V modify(int l,int r,int x) {
	if(bel[l]==bel[r]) {
		if(f2[bel[l]]) {
			fo(i,L[bel[l]],l-1) f[i]=f2[bel[l]];
			fo(i,r+1,R[bel[l]]) f[i]=f2[bel[l]];
		}
		fo(i,l,r) f[i]=x;
		rebuild(bel[l]);return ;
	}
	fo(i,bel[l]+1,bel[r]-1) f2[i]=g2[i]=x,s2[i]=1;
	fo(i,l,R[bel[l]]) f[i]=x;
	if(f2[bel[l]]) fo(i,L[bel[l]],l-1) f[i]=f2[bel[l]];
	rebuild(bel[l]);
	fo(i,L[bel[r]],r) f[i]=x;
	if(f2[bel[r]]) fo(i,r+1,R[bel[r]]) f[i]=f2[bel[r]];
	rebuild(bel[r]);
}
int main() {
//	fre(gua)
	n=read();m=read();
	B=sqrt(n);
	fo(i,1,n+1) bel[i]=(i-1)/B+1;
	fo(i,1,bel[n+1]) L[i]=(i-1)*B+1,R[i]=min(i*B,n+1),f2[i]=n+2,g2[i]=n+2,s2[i]=1;
	fo(i,1,m) {
		int op=read(),l=read(),r=read()+1;
		if(op==1) {
			int le=1,ri=l,a=l+1;
			while(le<=ri) {
				int mid=le+ri>>1;
				if(F(mid)>r) a=mid,ri=mid-1;
				else le=mid+1;
			}
			if(a<=l) modify(a,l,r);
		}
		else {
			int ans=0;
			while(G(l)<=r) ans+=S(l),l=G(l);
			while(F(l)<=r) ans++,l=F(l);
			printf("%d\n",ans);
		}
	}
	return 0;
}


详细

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:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%