求调,90分爆了RE(马蜂良好)

P1001 A+B Problem

chenzhishuo2012 @ 2024-08-14 09:31:59

第9个点爆了RE,求调,90分,算法:线段树

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
int read(void){
    int x=0;int w=1;char ch=0;
    while(!isdigit(ch)){if(ch=='-')w=-1;if(ch=='+')w=1;ch=getchar();}
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w*x;
}
void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int Left(int a){return a*2;}
int Right(int a){return a*2+1;}
int i,j,k,m,n,a[1000001],ans[1000001],Lazy[1000001],lazy[1000001];
void PushUp(int now){
    ans[now]=(ans[Left(now)]+ans[Right(now)]);
}
void Build(int now,int l,int r){
    if(l==r){ans[now]=a[l];return;}
    int mid=(l+r)/2;
    Build(Left(now),l,mid);
    Build(Right(now),mid+1,r);
    PushUp(now);
}
void Function(int now,int l,int r,int Add){
    Lazy[now]+=Add;
    ans[now]+=Add*(r-l+1);
}
void PushDown(int now,int l,int r){
    int mid=(l+r)/2;
    Function(Left(now),l,mid,Lazy[now]);
    Function(Right(now),mid+1,r,Lazy[now]);
    Lazy[now]=0;
}
void function(int now,int l,int r,int Add){
    Lazy[now]*=Add;
    lazy[now]*=Add;
    ans[now]*=Add;
}
void Push_Down(int now,int l,int r){
    int mid=(l+r)/2;
    function(Left(now),l,mid,lazy[now]);
    function(Right(now),mid+1,r,lazy[now]);
    lazy[now]=1;
}
void Data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]+=Add*(r-l+1);
        Lazy[now]+=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)Data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)Data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
void data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]*=Add;
        Lazy[now]*=Add;
        lazy[now]*=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
int Query(int NowL,int NowR,int l,int r,int now){
    int Return=0;
    if(NowL<=l&&NowR>=r)return ans[now];
    int mid=(l+r)/2;
    Push_Down(now,l,r);
    PushDown(now,l,r);
    if(NowL<=mid)Return+=Query(NowL,NowR,l,mid,Left(now));
    if(NowR>mid)Return+=Query(NowL,NowR,mid+1,r,Right(now));
    return Return;
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    n=2;
    int A=read(),B=read();
    Build(1,1,n);
    for(i=1;i<=n*4;i++)lazy[i]=1;
    int Gcd=gcd(A,B);
    Data(1,1,1,n,1,A/Gcd);
    Data(2,2,1,n,1,B/Gcd);
    data(1,2,1,n,1,Gcd);
    write(Query(1,2,1,n,1));
}

by 11514zbs @ 2024-08-14 09:46:36

@chenzhishuo2012

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
#include<algorithm>
using namespace std;
int read(void){
    int x=0;int w=1;char ch=0;
    while(!isdigit(ch)){if(ch=='-')w=-1;if(ch=='+')w=1;ch=getchar();}
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w*x;
}
void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int Left(int a){return a*2;}
int Right(int a){return a*2+1;}
int i,j,k,m,n,a[1000001],ans[1000001],Lazy[1000001],lazy[1000001];
void PushUp(int now){
    ans[now]=(ans[Left(now)]+ans[Right(now)]);
}
void Build(int now,int l,int r){
    if(l==r){ans[now]=a[l];return;}
    int mid=(l+r)/2;
    Build(Left(now),l,mid);
    Build(Right(now),mid+1,r);
    PushUp(now);
}
void Function(int now,int l,int r,int Add){
    Lazy[now]+=Add;
    ans[now]+=Add*(r-l+1);
}
void PushDown(int now,int l,int r){
    int mid=(l+r)/2;
    Function(Left(now),l,mid,Lazy[now]);
    Function(Right(now),mid+1,r,Lazy[now]);
    Lazy[now]=0;
}
void function(int now,int l,int r,int Add){
    Lazy[now]*=Add;
    lazy[now]*=Add;
    ans[now]*=Add;
}
void Push_Down(int now,int l,int r){
    int mid=(l+r)/2;
    function(Left(now),l,mid,lazy[now]);
    function(Right(now),mid+1,r,lazy[now]);
    lazy[now]=1;
}
void Data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]+=Add*(r-l+1);
        Lazy[now]+=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)Data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)Data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
void data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]*=Add;
        Lazy[now]*=Add;
        lazy[now]*=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
int Query(int NowL,int NowR,int l,int r,int now){
    int Return=0;
    if(NowL<=l&&NowR>=r)return ans[now];
    int mid=(l+r)/2;
    Push_Down(now,l,r);
    PushDown(now,l,r);
    if(NowL<=mid)Return+=Query(NowL,NowR,l,mid,Left(now));
    if(NowR>mid)Return+=Query(NowL,NowR,mid+1,r,Right(now));
    return Return;
}
int main(){
    n=2;
    int A=read(),B=read();
    if(A==0&&B==0)
    {
        write(0);
        return 0;
    }
    Build(1,1,n);
    for(i=1;i<=n*4;i++)lazy[i]=1;
    int Gcd=__gcd(A,B);
    Data(1,1,1,n,1,A/Gcd);
    Data(2,2,1,n,1,B/Gcd);
    data(1,2,1,n,1,Gcd);
    write(Query(1,2,1,n,1));
}

by gaoyunxuan0917 @ 2024-08-14 09:46:43

%%%


by 11514zbs @ 2024-08-14 09:47:09

@chenzhishuo2012 要是 a, b 都等于 0 呢?


by zheng_hehe @ 2024-08-14 11:18:42

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
int read(void){
    int x=0;int w=1;char ch=0;
    while(!isdigit(ch)){if(ch=='-')w=-1;if(ch=='+')w=1;ch=getchar();}
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w*x;
}
void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int Left(int a){return a*2;}
int Right(int a){return a*2+1;}
int i,j,k,m,n,a[1000001],ans[1000001],Lazy[1000001],lazy[1000001];
void PushUp(int now){
    ans[now]=(ans[Left(now)]+ans[Right(now)]);
}
void Build(int now,int l,int r){
    if(l==r){ans[now]=a[l];return;}
    int mid=(l+r)/2;
    Build(Left(now),l,mid);
    Build(Right(now),mid+1,r);
    PushUp(now);
}
void Function(int now,int l,int r,int Add){
    Lazy[now]+=Add;
    ans[now]+=Add*(r-l+1);
}
void PushDown(int now,int l,int r){
    int mid=(l+r)/2;
    Function(Left(now),l,mid,Lazy[now]);
    Function(Right(now),mid+1,r,Lazy[now]);
    Lazy[now]=0;
}
void function(int now,int l,int r,int Add){
    Lazy[now]*=Add;
    lazy[now]*=Add;
    ans[now]*=Add;
}
void Push_Down(int now,int l,int r){
    int mid=(l+r)/2;
    function(Left(now),l,mid,lazy[now]);
    function(Right(now),mid+1,r,lazy[now]);
    lazy[now]=1;
}
void Data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]+=Add*(r-l+1);
        Lazy[now]+=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)Data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)Data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
void data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]*=Add;
        Lazy[now]*=Add;
        lazy[now]*=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
int Query(int NowL,int NowR,int l,int r,int now){
    int Return=0;
    if(NowL<=l&&NowR>=r)return ans[now];
    int mid=(l+r)/2;
    Push_Down(now,l,r);
    PushDown(now,l,r);
    if(NowL<=mid)Return+=Query(NowL,NowR,l,mid,Left(now));
    if(NowR>mid)Return+=Query(NowL,NowR,mid+1,r,Right(now));
    return Return;
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    n=2;
    int A=read(),B=read();
    int ans=A+B;
    write(ans);
}

by zheng_hehe @ 2024-08-14 11:19:37

@chenzhishuo2012 我的AC了


by chenzhishuo2012 @ 2024-08-14 11:52:33

@114514zbs 本人已AC 谢谢指导%%%


by wyc_dream @ 2024-08-15 10:19:08

666


by __crz_qaq__ @ 2024-08-15 13:45:59

奆佬%%%


by hebaodan @ 2024-09-04 15:16:25

直接cout<<a+b;不行吗?


|