蒟蒻下载了测试数据检查过结果是对的结果零分,谁能帮帮我
查看原帖
蒟蒻下载了测试数据检查过结果是对的结果零分,谁能帮帮我
306954
芊枫Thomitics楼主2020/7/1 15:31
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 300090;

bool nums[MAXN];
long long totN;
long long totDO;
bool tempquest;

struct Node
{
    bool tag;
    long long value;
    long long l, r;
    Node* lch, * rch;
    inline void maketag()
    {
        value = r - l - value + 1;
        tag ^= 1;
    }
    inline void push_up()
    {
        value = lch->value + rch->value;
    }
    inline void push_down()
    {
        if (!tag)
        {
            return;
        }
        else
        {
            lch->maketag();
            rch->maketag();
            tag ^= 1;
        }
    }
    Node(const long long L, const long long R)
    {
        l = L;
        r = R;
        if (l == r)
        {
            value = nums[l];
            lch = NULL;
            rch = NULL;
            tag = 0;
        }
        else
        {
            tag = 0;
            long long mid = (l + r) >> 1;
            lch = new Node(L, mid);
            rch = new Node(mid + 1, R);
            push_up();
        }
    }
    inline bool in_range(const long long L, const long long R)
    {
        return (L <= l) && (R >= r);
    }
    inline bool out_of_range(const long long L, const long long R)
    {
        return (l > R) || (r < L);
    }
    inline void update(const long long L, const long long R)
    {
        if (in_range(L, R))
        {
            maketag();
        }
        else if (!out_of_range(L, R))
        {
            push_down();
            lch->update(L, R);
            rch->update(L, R);
            push_up();
        }
    }
    inline long long quest_range_sum(const long long L, const long long R)
    {
        if (in_range(L, R))
        {
            return value;
        }
        else
        {
            if (out_of_range(L, R))
            {
                return 0;
            }
        }
        push_down();
        return lch->quest_range_sum(L, R) + rch->quest_range_sum(L, R);
    }
};

inline long long read()
{
    long long x = 0;
    short f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}

int main()
{
    totN = read();
    totDO = read();
    int temp;
    for (int i = 1; i <= totN; i++)
    {
        nums[i] = getchar() - '0';
    }
    getchar();
    Node* root = new Node(1, totN);
    for (int i = 1; i <= totDO; i++)
    {
        tempquest = read();
        if (!tempquest)
        {
            long long tempL = read();
            long long tempR = read();
            root->update(tempL, tempR);
        }
        else
        {
            long long tempL = read();
            long long tempR = read();
            printf("%lld\n",root->quest_range_sum(tempL, tempR));
        }
    }
    return 0;
}

2020/7/1 15:31
加载中...