2019 Nanchang Online Contest Problem I Yukino With Subinterval

54 篇文章 0 订阅

#include<bits/stdc++.h>
using namespace std;
#define maxn 2000005
int s,w,n,cnt;
int ans[maxn],sum[maxn],A[maxn];
struct data{int x,y,z,pos,id;}a[maxn],b[maxn];
inline bool cmp(data a,data b){
if (a.x==b.x&&a.y==b.y) return a.pos<b.pos;
else if (a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
for(int i=x;i<=w;i+=i&(-i)) sum[i]+=v;
}
inline int query(int x){
int ret=0;
for(int i=x;i;i-=i&(-i)) ret+=sum[i];
return ret;
}
inline void solve(int l,int r){
if (l==r) return;
int mid=(l+r)/2,l1=l,l2=mid+1;
for(int i=l;i<=r;++i){
if (a[i].id>mid&&a[i].pos) ans[a[i].pos]+=query(a[i].y)*a[i].z;
}
for(int i=l;i<=r;++i){
if (a[i].id<=mid) b[l1++]=a[i];
else b[l2++]=a[i];
}
for(int i=l;i<=r;++i) a[i]=b[i];
solve(l,mid);solve(mid+1,r);
}
int main(){
s=0;
int m,x,y,z;cin>>w>>m;
for(int i=1;i<=w;++i)scanf("%d",&A[i]);
for(int i=1;i<=w;++i){
if(A[i]==A[i-1]){
x=i-1;y=A[i-1];z=-1;
n++;a[n]=(data){x,y,z,0,n};
}
x=i;y=A[i];z=1;
n++;a[n]=(data){x,y,z,0,n};
}
while(m--){
int op;scanf("%d",&op);
if (op==1){
scanf("%d%d",&x,&y);
if(A[x]==y)continue;
if(A[x]==A[x-1]&&A[x]==A[x+1]){
}else if(A[x]==A[x-1]&&A[x]!=A[x+1]){
}else if(A[x]!=A[x-1]&&A[x]==A[x+1]){
}else if(A[x]!=A[x-1]&&A[x]!=A[x+1]){
if(y==A[x-1]&&y==A[x+1]){
}
if(y==A[x-1]&&y!=A[x+1]){
}
if(y!=A[x-1]&&y!=A[x+1]){
}
}
A[x]=y;
}
else {
int x1,x2,y1,y2;scanf("%d%d%d%d",&x1,&x2,&y1,&y2);--x1,--y1;
ans[++cnt]=(x2-x1)*(y2-y1)*s;
n++;a[n]=(data){x1,y1,1,cnt,n};
n++;a[n]=(data){x1,y2,-1,cnt,n};
n++;a[n]=(data){x2,y1,-1,cnt,n};
n++;a[n]=(data){x2,y2,1,cnt,n};
}
}
sort(a+1,a+n+1,cmp);
solve(1,n);
for(int i=1;i<=cnt;i++) printf("%d\n",ans[i]);
}

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

09-10 253
12-04 304