# 做法

#include<cstdio>
#include<algorithm>
#include<queue>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10,B=3;
int belong[maxn],val[maxn],sum[maxn],fi[maxn];
int L[maxn],R[maxn],data[maxn],a[maxn],b[maxn],c[maxn],id[maxn];
struct dong{
int x,y,v;
friend bool operator <(dong a,dong b){
return a.x<b.x||a.x==b.x&&a.y<b.y;
}
} p[maxn*4];
queue<int> dl[maxn];
int x=0,f=1;
char ch=getchar();
while (ch<'0'||ch>'9'){
if (ch=='-') f=-1;
ch=getchar();
}
while (ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void ins(int id,int f){
if (id>m) return;
if (L[id]<=l&&R[id]>=r){
return;
}
else if (R[id]<l||L[id]>r) return;
int i,j=l,k=r;
j=max(j,L[id]);
k=min(k,R[id]);
fo(i,j,k) val[i]-=f;
mx=0;
fo(i,l,r) mx=max(mx,val[i]);
}
void work(int p,int q){
int i,j,k;
fo(i,p,q){
tot=0;
while (!dl[i].empty()){
id[++tot]=dl[i].front();
dl[i].pop();
}
k=0;
fo(j,1,tot){
while (k<=tot&&sum[id[k]]-sum[id[j]]+k-j<a[i]) k++;
if (k>tot){
t=a[i]-(tot-j)+sum[id[j]];
if (t>len) b[id[j]]=m+1;
else b[id[j]]=max(b[id[j]],fi[t]);
}
else{
if (sum[id[k]]-sum[id[j]]+k-j==a[i]) b[id[j]]=max(b[id[j]],id[k]);
else{
t=a[i]-(k-j-1)+sum[id[j]];
t=fi[t];
b[id[j]]=max(b[id[j]],t);
}
}
}
}
}
int main(){
freopen("data.in","r",stdin);freopen("data.out","w",stdout);
fo(i,1,m){
mx=max(mx,data[i]);
}
top=mx;
fo(i,1,n) belong[i]=(i-1)/B+1;
fo(i,1,m){
l=belong[L[i]];r=belong[R[i]];
if (l==r){
if ((l-1)*B+1==L[i]&&min(r*B,n)==R[i]) continue;
fo(j,L[i],R[i]) dl[j].push(i);
}
else{
if (L[i]!=(l-1)*B+1) fo(j,L[i],l*B) dl[j].push(i);
if (R[i]!=min(r*B,n)) fo(j,(r-1)*B+1,R[i]) dl[j].push(i);
}
}
fo(i,1,belong[n]){
l=(i-1)*B+1;r=min(i*B,n);
fo(j,l,r){
val[j]=a[j];
mx=max(mx,a[j]);
}
ins(k=1,1);
fo(j,1,m){
ins(j,-1);
if (L[j]<=l&&r<=R[j]) b[j]=max(b[j],k);
}
fo(j,1,m){
sum[j]=sum[j-1];
if (L[j]<=l&&r<=R[j]){
sum[j]++;
fi[sum[j]]=j;
}
}
len=sum[m];
work(l,r);
}
tot=0;
fo(i,1,m){
tot++;
p[tot].x=data[i];
p[tot].y=i;
p[tot].v=1;
tot++;
p[tot].x=data[i];
p[tot].y=b[i];
p[tot].v=-1;
}
mx=top;
fo(i,1,mx){
tot++;
p[tot].x=i;
p[tot].y=1;
p[tot].v=0;
tot++;
p[tot].x=i;
p[tot].y=m+1;
p[tot].v=0;
}
sort(p+1,p+tot+1);
r=0;
fo(i,1,mx){
t=0;
l=r+1;
while (r<tot&&p[r+1].x==i) r++;
fo(j,l,r-1){
t+=p[j].v;
if (t){
c[p[j].y]++;
c[p[j+1].y]--;
}
}
}
t=0;
fo(i,1,m){
t+=c[i];
printf("%d\n",t);
}
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120