社区讨论

怎么T了

P3373【模板】线段树 2参与者 5已保存回复 17

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
17 条
当前快照
1 份
快照标识符
@mi7coizr
此快照首次捕获于
2025/11/20 19:30
4 个月前
此快照最后确认于
2025/11/20 21:59
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
#define endl '\n'

class fastIO {
private:
    char rbuf[100000], wbuf[100000], *p1, *p2, *p3;
    int l, tag;
    inline char get(void) {
        return p1 == p2 && (p2 = (p1 = rbuf) + fread(rbuf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
    }
    inline void put(char x) {
        l == 100000 ? (p3 = wbuf, fwrite(wbuf, 1, 100000, stdout), l = 1, *p3++ = x) : (l++, *p3++ = x);
        return;
    }
public:
    fastIO() : l(0), p1(rbuf), p2(rbuf), p3(wbuf), tag(0) {}
    ~fastIO() {fwrite(wbuf, 1, l, stdout);}
    inline void putLine(const char* x) {
        fwrite(wbuf, 1, l, stdout);
        fwrite(x, 1, strlen(x), stdout);
        l = 0;
        p3 = wbuf;
        return;
    }
    inline void getLine(std::string& x) {
        x.clear();
        char c = get();
        while ((c < 33 || c > 126) && c != EOF) c = get();
        if (c == EOF) tag = 1;
        while ((c >= 33 && c <= 126) || c == ' ') {
            x += c;
            c = get();
        }
        return;
    }
template <typename T>
    inline fastIO& operator >> (T& x) {
        x = 0;
        bool f = 0;
        char c = get();
        while (!isdigit(c) && c != EOF) {
            f |= (c == '-');
            c = get();
        }
        if (c == EOF) tag = 1;
        while (isdigit(c)) {
            x = (x << 1) + (x << 3) + (c ^ 48);
            c = get();
        }
        x = f ? ~x + 1 : x;
        return *this;
    }
    inline fastIO& operator >> (char& x) {
        x = get();
        while ((x < 33 || x > 126) && x != EOF) {
            if (x == EOF) tag = 1;
            x = get();
        }
        return *this;
    }
    inline fastIO& operator >> (std::string& x) {
        x.clear();
        char c = get();
        while ((c < 33 || c > 126) && c != EOF) c = get();
        if (c == EOF) tag = 1;
        while (c >= 33 && c <= 126) {
            x += c;
            c = get();
        }
        return *this;
    }
template <typename Y>
    inline fastIO& operator << (Y x) {
        int putList[25];
        int cnt = 0;
        !x ? (put('0'), 0) : 0;
        x < 0 ? (put('-'), x = ~x + 1) : 0;
        while (x > 0) {
            putList[++cnt] = x % 10 + 48;
            x /= 10;
        }
        while (cnt) put(putList[cnt--]);
        return *this;
    }
    inline fastIO& operator << (char* x) {return putLine(x), *this;}
    inline fastIO& operator << (char x) {return put(x), *this;}
    inline fastIO& operator << (const std::string& x) {return putLine(x.c_str()), *this;}
    inline operator bool() {return tag ? 0 : 1;}
}io;

long long p;

struct node {
    long long l, r, TeRi, lazyAdd, lazyCheng;
    node* child[2];
    node(long long lty = 0, long long yzl = 0) : l(lty), r(yzl), TeRi(0), lazyAdd(0), lazyCheng(1) {
        child[0] = child[1] = NULL;
    }
}*root, point[300010];

inline node* newnode(long long lty, long long yzl) {
    static int cnt = 0;
    node* o = &point[cnt++];
    o->l = lty;
    o->r = yzl;
    return o;
}

inline void pushDown(node* o) {
    if (o->child[0]) {
        o->child[0]->lazyCheng *= o->lazyCheng;
        o->child[0]->lazyCheng %= p;
        o->child[0]->lazyAdd *= o->lazyCheng;
        o->child[0]->lazyAdd %= p;
        o->child[0]->lazyAdd += o->lazyAdd;
        o->child[0]->lazyAdd %= p;
    }
    if (o->child[1]) {
        o->child[1]->lazyCheng *= o->lazyCheng;
        o->child[1]->lazyCheng %= p;
        o->child[1]->lazyAdd *= o->lazyCheng;
        o->child[1]->lazyAdd %= p;
        o->child[1]->lazyAdd += o->lazyAdd;
        o->child[1]->lazyAdd %= p;
    }
    o->TeRi *= o->lazyCheng;
    o->TeRi %= p;
    o->TeRi += o->lazyAdd * (o->r - o->l) % p;
    o->TeRi %= p;
    o->lazyCheng = 1;
    o->lazyAdd = 0;
    return;
}

回复

17 条回复,欢迎继续交流。

正在加载回复...