这题咋做?

P1001 A+B Problem

Konjac_WGR @ 2023-03-14 12:52:41

RT


by ragwort @ 2023-03-14 12:54:55

没活整可以【】


by ragwort @ 2023-03-14 12:55:20

@Konjac_WGR 可以用线段树和并查集


by _Adolf_Hitler_ @ 2023-03-14 12:55:25

你个绿名还做不出来?

强烈怀疑盗号


by Konjac_WGR @ 2023-03-14 12:56:12

@wind_kaka %%% sto orz


by _Adolf_Hitler_ @ 2023-03-14 12:58:22

#include <bits/stdc++.h>

using namespace std;

inline namespace fastmath{
    typedef long long ll;
    typedef unsigned long long ull;
    typedef __uint128_t L;

    inline ll ABS(ll n);
    inline ll ADD(ll a, ll b);
    inline ll SUB(ll a, ll b);
    inline ll MUL(ll a, ll b);
    inline ll DIV(ll a, ll b);
    inline ll POW(ll a, ll b, ll mod);
    inline ull MOD(ull a, ull b);

    inline ll ABS(ll n){
        return (n ^ (n >> 63)) - (n >> 63);
    }

    inline ll ADD(ll a, ll b){
        if (a < 0 && b < 0){
            return -ADD(-a, -b);
        }
        if (a < 0){
            return SUB(b, -a);
        }
        if (b < 0){
            return SUB(a, -b);
        }
        while (b > 0){
            ll carry = a & b;
            a ^= b;
            b = carry << 1;
        }
        return a;
    }

    inline ll SUB(ll a, ll b){
        if (a < 0 && b < 0){
            return -SUB(-a, -b) + 1;
        }
        if (a < 0){
            return ADD(-a, b);
        }
        if (b < 0){
            return ADD(a, -b);
        }
        while (b != 0){
            ll carry = (~a) & b;
            a = a ^ b;
            b = carry << 1;
        }
        return a;
    }

    inline ll MUL(ll a, ll b){
        ll x = ABS(a), y = ABS(b), res = 0;
        bool neg = false;
        if (min(a, b) < 0 && max(a, b) >= 0){
            neg = true;
        }
        while(y > 0){
            if ((y & 1) == 1){
                res += x;
            }
            y >>= 1; x <<= 1;
        }
        if (neg){
            return (~(res) + 1);
        }
        else{
            return res;
        }
    }

    inline ll DIV(ll a, ll b){
        if (a < 0 && b < 0){
            return DIV(-a, -b);
        }
        if (a < 0){
            return -DIV(-a, b);
        }
        if (b < 0){
            return -DIV(a, -b);
        }
        int tmp = 1, res = 0;
        while (b <= a){
            b <<= 1;
            tmp <<= 1;
        }
        while (tmp > 1){
            b >>= 1;
            tmp >>= 1;
            if (a >= b){
                a -= b;
                res += tmp;
            }
        }
        return res;
    }

    inline ll POW(ll base, ll exponent, ll mod=LLONG_MAX){
        ll x = 1;
        ll y = base;
        while (exponent > 0){
            if (MOD(exponent, 2) == 1){
                x = MOD((x * y), mod);
            }
            y = MOD((y * y), mod);
            exponent >>= 1;
        }
        return MOD(x, mod);
    }

    struct FastMod{
        ull b, m;
        FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
        ull reduce(ull a) {
            ull q = (ull)((L(m) * a) >> 64);
            ull r = a - q * b;
            return r >= b ? r - b : r;
        }
    };

    FastMod F(2);

    inline ull MOD(ull a, ull b){
        F = FastMod(b);
        return F.reduce(a);
    }
}

#include <bits/stdc++.h>

using namespace std;

inline namespace FastIO{
    const int bufferSize = 1 << 15;
    inline namespace FastInput{
        // INPUT
        char inputBuffer[bufferSize]; int iPosition, iLength;

        char next_char(){
            if (iPosition == iLength){
                iPosition = 0; iLength = fread(inputBuffer, 1, bufferSize, stdin);
                if (!iLength) return EOF;
            }
            return inputBuffer[iPosition++];
        }

        void read_string(string &x){
            char ch; while(isspace(ch = next_char())){};
            do {
                x += ch;
            } while(!isspace(ch = next_char()) && ch!= '\n');
        }

        template<class T> void read_int(T &x){ // read int OR long long
            char ch; int sign = 1;
            while (!isdigit(ch = next_char())){
                if (ch == '-') sign *= -1;
            }
            x = ch - '0';
            while (isdigit(ch = next_char())){
                x = x * 10 + (ch - '0');
            }
            x *= sign;
        }

        template<class T, class... Ts> void read_int(T& t, Ts&... ts){
            read_int(t); read_int(ts...);
        }
    }
    inline namespace fastOutput{
        // OUTPUT (call initO() at start)
        char outBuffer[bufferSize], numberBuffer[100]; int outPosition;
        void flushOut(){
            fwrite(outBuffer, 1, outPosition, stdout);
            outPosition = 0;
        }

        void write_char(char c){
            if (outPosition == bufferSize){
                flushOut();
            }
            outBuffer[outPosition++] = c;
        }

        void write_string(string s){
            for (char c : s){
                write_char(c);
            }
        }

        template<class T> void write_int(T x, char after = '\0'){
            if (x < 0){
                write_char('-');
                x = x * -1;
            }
            int length = 0;
            for (; x >= 10; x /= 10){
                numberBuffer[length ++] = '0' + (x % 10);
            }
            write_char('0' + x);
            for (int i = length - 1; i >= 0; i --){
                write_char(numberBuffer[i]);
            }
            if (after){
                write_char(after);
            }
        }

        void initO(){
            assert(atexit(flushOut) == 0);
        }
    }
}

int main(){
    initO();
    int a, b;
    read_int(a, b);
    write_int(ADD(a, b), '\n');
    return 0;
}

by 2949767807qwer @ 2023-03-14 12:58:46

可以使用Link-Cat Tree(连猫树)来做


by _Adolf_Hitler_ @ 2023-03-14 12:59:41

AC代码奉上


by RP_INT_MAX @ 2023-03-14 13:01:03

@Konjac_WGR NTT


by Konjac_WGR @ 2023-03-14 13:01:39

@2949767807qwer %%%


by Konjac_WGR @ 2023-03-14 13:01:56

@RP_INT_MAX %%%


| 下一页