LOJ # 3043. "ZJOI2019" árvore de segmento de linha árvore de segmento de linha + discussão sobre classificação

Da Da é dividido em discussões, e as idéias ainda são muito inteligentes. 

código: 

#include <bits / stdc ++. h>     
#define ll long long 
#define lson now << 1 
#define rson now << 1 | 1     
#define N 100008         
#define mod 998244353 
#define setIO (s) freopen (s ".in "," r ", stdin) 
usando o namespace std;    
int n, m, cur;   
ll f [N << 3], g [N << 3], SUM [N << 3], qp [N], MF [N << 3], mg [N << 3];  
void markf (int agora, int v) 
{ 
    f [agora] = (ll) f [agora] * qp [v]% mod;     
    SUM [agora] = (ll) SUM [agora] * qp [v]% mod;  
    mf [agora] + = v;    
}     
void markg (int agora, int v) 
{ 
    g [agora] = (ll) g [agora] * qp [v]% mod;    
    mg [agora] + = v;  
    if (mf [agora]) 
void update (int l, int r, int agora, int L, int R)
    { 
        markf (lson, mf [agora]); 
        markf (rson, mf [agora]); 
        mf [agora] = 0;   
    } 
    if (mg [agora]) 
    { 
        markg (lson, mg [agora]); 
        markg (rson, mg [agora]);  
        mg [agora] = 0;   
    } 
} 
void pushup (int now) 
{   
    SUM [now] = (ll) (SUM [lson] + SUM [rson] + f [now])% mod;    
}   
void build (int l, int r, int agora) 
{ 
    f [agora] = 0, g [agora] = 1;   
    se (l == r) retornar;      
    int médio = (l + r) >> 1;   
    build (l, mid, lson), build (mid + 1, r, rson);    
}        
{      
    pushdown (agora);             
    if (l> = L && r <= R)
        pushdown (p);   
    {     
        // 1 点    
        [f [agora] = (ll) (f [agora] + qp [cur-1])% mod;             
        markf (lson, 1), markf (rson, 1);                         
        flexão (agora);               
        Retorna;    
    } 
    int mid = (l + r) >> 1;   
    if (L <= médio && R> médio) 
    {    
        update (l, mid, lson, L, R); 
        atualização (média + 1, r, rson, L, R);                 
    } 
    else if (L <= médio) 
    { 
        update (l, mid, lson, L, R);      
        int p = rson;               
        markf (p << 1,1), markf (p << 1 | 1,1);     
        markg (p << 1,1), markg (p << 1 | 1,1);       
        g [p] = (ll) (g [p] + g [p])% mod;     
        flexão (p);     
    } 
    else 
    {        
 
        update (médio + 1, r, rson, L, R);   
        int p = lson;                       
        pushdown (p);   
        markf (p << 1,1), markf (p << 1 | 1,1);     
        markg (p << 1,1), markg (p << 1 | 1,1);  
        f [p] = (ll) (f [p] + qp [cur-1] -g [p] + mod)% mod;     
        g [p] = (ll) (g [p] + g [p])% mod;  
        flexão (p);        
    }                  
    // 2 类 点      
    // 
    g [agora] = (ll) (g [agora] + qp [cur-1])% mod;   
    flexão (agora);          
} 
int main ()
{ 
   // setIO ("entrada"); 
    qp [0] = 1;   
    para (int i = 1; i <N; ++ i) qp [i] = (ll) qp [i-1] * 2% mod;      
    scanf ("% d% d", & n, & m);    
    construir (1, n, 1);   
    for (int i = 1; i <= m; ++ i) 
    {    
        int op, l, r;   
        scanf ("% d", & op);  
        if (op == 1)      
        { 
            scanf ("% d% d", & l, & r), ++ cur, update (1, n, 1, l, r);   
        } 
        else 
        { 
            printf ("% lld \ n", SUM [1]);    
        } 
    } 
    retornar 0; 
}

  

Acho que você gosta

Origin www.cnblogs.com/guangheli/p/12748685.html
Recomendado
Clasificación