QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#112037 | #4894. 学姐买瓜 | zhouhuanyi | 0 | 0ms | 0kb | C++11 | 2.1kb | 2023-06-09 16:18:35 | 2023-06-09 16:18:36 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#define N 400000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,m,sz,sn,lg[N+1],block[N+1],nt[N+1],nts[N+1],cnt[N+1],lazy[N+1];
void rebuild(int k)
{
for (int i=min(k*sz,sn);i>=(k-1)*sz+1;--i)
{
if (nt[i]>min(k*sz,sn)) nts[i]=nt[i],cnt[i]=1;
else nts[i]=nts[nt[i]],cnt[i]=cnt[nt[i]]+1;
}
return;
}
void spread(int k)
{
if (lazy[k]!=-1)
{
for (int i=(k-1)*sz+1;i<=min(k*sz,sn);++i) nt[i]=lazy[k];
lazy[k]=-1;
}
return;
}
void adder(int l,int r,int d)
{
if (block[l]==block[r])
{
spread(block[l]);
for (int i=l;i<=r;++i) nt[i]=d;
rebuild(block[l]);
}
else
{
spread(block[l]),spread(block[r]);
for (int i=l;i<=min(block[l]*sz,sn);++i) nt[i]=d;
for (int i=block[l]+1;i<=block[r]-1;++i) lazy[i]=d;
for (int i=(block[r]-1)*sz+1;i<=r;++i) nt[i]=d;
rebuild(block[l]),rebuild(block[r]);
}
return;
}
int get_nt(int x)
{
if (lazy[block[x]]!=-1) return lazy[block[x]];
else return nt[x];
}
int get_nts(int x)
{
if (lazy[block[x]]!=-1) return lazy[block[x]];
else return nts[x];
}
int get_cnt(int x)
{
if (lazy[block[x]]!=-1) return 1;
else return cnt[x];
}
int query(int l,int r)
{
int x=l,res=0;
while (get_nts(x)<=r+1) res+=get_cnt(x),x=get_nts(x);
while (nt[x]<=r+1) x=nt[x],res++;
return res;
}
int main()
{
int op,l,r,x;
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
n=read(),m=read(),sz=sqrt(n),sn=n+1;
for (int i=1;i<=sn;++i) nt[i]=nts[i]=inf,block[i]=(i-1)/sz+1;
for (int i=1;i<=block[sn];++i) lazy[i]=-1;
for (int i=1;i<=m;++i)
{
op=read(),l=read(),r=read();
if (op==1)
{
x=0;
for (int j=lg[n];j>=0;--j)
if (x+(1<<j)<=l&&get_nt(x+(1<<j))<=r+1)
x+=(1<<j);
x++;
if (x<=l) adder(x,l,r+1);
}
else printf("%d\n",query(l,r));
}
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%