WA,玄关求条
查看原帖
WA,玄关求条
1565595
xtzhangziche楼主2025/7/31 10:44
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,c[100005],h[100005];
int lowbit(int x){
    return x&(-x);
}
void add(int x,int v){
    for(;x<=n;x+=lowbit(x))
        c[x]+=v;
}
int sum(int x){
    int s=0;
    for(;x>0;x-=lowbit(x))
        s+=c[x];
    return s;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    while(n--)
    {
     int l,r;
     cin>>l>>r;
     int ll=sum(l);
	 int rr=sum(r);
	 cout<<ll-h[l]+rr-h[r]<<'\n';
	 h[l]=ll;
	 h[r]=rr;
	 if(l+1<=r-1) add(l+1,1),add(r,-1);
    }
    return 0;
}
2025/7/31 10:44
加载中...