相邻两行代码的输出结果不一样?
  • 板块学术版
  • 楼主262620zzj
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/14 14:51
  • 上次更新2024/8/14 16:11:08
查看原帖
相邻两行代码的输出结果不一样?
575698
262620zzj楼主2024/8/14 14:51
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
template<typename T,typename ...Args>
inline void read(T &x,Args &...rest){read(x);read(rest...);}
constexpr int N=4e5+5,M=1048577;
int cnt[M],len[M],n,dctx[N],totx;
#define ls (p<<1)
#define rs (p<<1|1)
inline void add(int p,int l,int r,int L,int R,int tt){
    if(r<L||R<l)return;
    if(L<=l&&r<=R){
        cnt[p]+=tt;
        if(cnt[p])len[p]=dctx[r]-dctx[l];
        else len[p]=len[ls]+len[rs];
        return;
    }
    add(ls,l,l+r>>1,L,R,tt);
    add(rs,(l+r>>1)+1,r,L,R,tt);
    if(cnt[p])len[p]=dctx[r]-dctx[l];
    else len[p]=len[ls]+len[rs];
}
struct Line{
    int l,r,y,w;
    Line(int a=0,int b=0,int c=0,int d=0){l=a,r=b,y=c,w=d;}
    bool operator < (const Line &b)const{return y<b.y;}
};
vector<Line>line;
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        int a,b,c,d;read(a,b,c,d);
        dctx[++totx]=a,dctx[++totx]=c;
        line.push_back(Line(a,c,b,1));
        line.push_back(Line(a,c,d+1,-1));
    }
    sort(line.begin(),line.end());
    sort(dctx+1,dctx+1+totx);
    totx=unique(dctx+1,dctx+1+totx)-dctx-1;
    // for(int i=1;i<=totx;i++)cerr<<dctx[i]<<' ';cerr<<endl;
    for(auto z:line){
        z.l=lower_bound(dctx+1,dctx+1+totx,z.l)-dctx;
        z.r=lower_bound(dctx+1,dctx+1+totx,z.r)-dctx;
        cout<<z.l<<' '<<z.r<<' '<<z.y<<' '<<z.w<<endl;
    }
    for(auto z:line)cout<<z.l<<' '<<z.r<<' '<<z.y<<' '<<z.w<<endl;
    long long ans=0;
    for(int i=0;i<line.size();i++){
        add(1,1,totx,line[i].l,line[i].r,line[i].w);
        ans+=1ll*len[1]*(line[i].y-line[i-1].y);
    }
    printf("%lld\n",ans);
    return 0;
}

第一次输出离散化之后的,第二次输出原来的

2024/8/14 14:51
加载中...