70 pts 求助,TLE 3 个点,但下载数据后在本地测能很快跑出

P1253 扶苏的问题

huangkx @ 2022-01-31 15:28:25

RT

#include <bits/stdc++.h>
using namespace std;
template < typename T > inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool flag = false;
    while(c < '0' || c > '9') if(c == '-') flag = true, c = getchar();
    while('0' <= c && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    if(flag) x = -x;
}
template < typename T > inline void write(T x)
{
    short s[64];
    short top = 0;
    if(x < 0) putchar('-'), x = -x;
    do s[++top] = x % 10, x /= 10; while(x);
    while(top) putchar('0' | s[top--]);
}
void solve();
int main()
{
    solve();
    return 0;
}
#define int long long
struct Chtholly_Tree{
    #define SIT set <node> :: iterator
    struct node{
        int l, r;
        mutable int v;
        bool operator < (const node &a) const {return l < a.l;}
        node(int L, int R, int V): l(L), r(R), v(V){}
        node(int L): l(L){}
    };
    set <node> s;
    void init(int p, int v)
    {
        s.insert(node(p, p, v));
    }
    SIT split(int p)
    {
        SIT it = s.lower_bound(node(p));
        if(it -> l == p && it != s.end()) return it;
        it--;
        int l = it -> l, r = it -> r, v = it -> v;
        s.erase(it);
        s.insert(node(l, p-1, v));
        return s.insert(node(p, r, v)).first;
    }
    void assign(int l, int r, int v)
    {
        SIT it_l, it_r;
        it_r = split(r+1);
        it_l = split(l);
        s.erase(it_l, it_r);
        s.insert(node(l, r, v));
    }
    void add(int l, int r, int v)
    {
        SIT it_l, it_r;
        it_r = split(r+1);
        it_l = split(l);
        for(SIT it=it_l; it!=it_r; it++) it -> v += v;
    }
    int get_max(int l, int r)
    {
        SIT it_l, it_r;
        it_r = split(r+1);
        it_l = split(l);
        int res = -1e18;
        for(SIT it=it_l; it!=it_r; it++) res = max(res, it->v);
        return res;
    }
};
Chtholly_Tree tree;
int n, q;
int opt, l, r, x;
void solve()
{
    read(n), read(q);
    for(int i=1; i<=n; i++){
        read(x);
        tree.init(i, x);
    }
    for(int i=1; i<=q; i++){
        read(opt), read(l), read(r);
        if(opt == 1){
            read(x);
            tree.assign(l, r, x);
        }
        if(opt == 2){
            read(x);
            tree.add(l, r, x);
        }
        if(opt == 3){
            write(tree.get_max(l, r));
            putchar('\n');
        }
    }
}
//珂朵莉树

by huangkx @ 2022-01-31 15:45:34

原来要卡珂朵莉树。。。此贴终结。


|