谁能帮帮我
查看原帖
谁能帮帮我
1382496
myl_coder楼主2024/7/26 14:03

家人们谁懂啊

c++这么难啊!!!

我辛辛苦苦写了这么多

才10分

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define pii pair<ll,ll>
const ll INF=1e18;
const ll DMAX=1000000+15;
const ll MOD=1000000007;
const ll G=3;
const ll invG=332748118;
ll ans;

ll n, m;

ll a[DMAX];
int q;
struct SegTree{
    ll tag,sum;
    int l,r;
    SegTree(){
        tag=sum=0;
    }
};
SegTree tr[DMAX];
void pushup(int p){
    tr[p].sum=tr[p<<1].sum+tr[p<<1|1].sum;
}
void build(int p,int l,int r){
    tr[p].l=l,tr[p].r=r;
    if(l==r){
        tr[p].sum=a[l];
        return ;
    }
    int mid=(l+r)>>1;
    build(p<<1,l,mid);
    build(p<<1|1,mid+1,r);
    pushup(p);
}

template<class T> inline void read(T &x){
    x=0;
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}

template<class T> void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    int a[20];
    int cnt=0;
    do{
        a[++cnt]=x%10;
        x/=10;
    }while(x>0);
    for(int i=cnt;i>=1;i--){
        putchar(a[i]+'0');
    }
    puts("");
}

void spread(int p){
    if(tr[p].tag){
        tr[p<<1].tag+=tr[p].tag,tr[p<<1|1].tag+=tr[p].tag;
        tr[p<<1].sum+=(tr[p<<1].r-tr[p<<1].l+1)*tr[p].tag;
        tr[p<<1|1].sum+=(tr[p<<1|1].r-tr[p<<1|1].l+1)*tr[p].tag;
        tr[p].tag=0;
    }
}

void add(int p,int l,int r,ll val){
    if(l<=tr[p].l && tr[p].r<=r){
        tr[p].sum+=ll(tr[p].r-tr[p].l+1)+val;
        ++ ans;
        tr[p].tag+=val;
        return ;
    }
    spread(p);
    int mid=(tr[p].l+tr[p].r)>>1;
    if(l<=mid){
        add(p<<1,l,r,val);
    }
    if(r>mid){
        add(p<<1|1,l,r,val);
    }
    pushup(p);
}

signed main () {
    
    read(n);
    read(m);
    
    build(1,1,m);
    
    
    for (int i = n; i <= m; i ++) {
		add (1, i, i, 1);
	}
	ans += n;
	write (ans);
    
    return 0;
}
2024/7/26 14:03
加载中...