• HDU 5068 Harry And Math Teacher


    主题链接~~>

    做题情绪:的非常高深,有种高大上的感觉。

    解题思路:

                    两层之间的联通能够看成是一个矩阵  代表上下两层都能够联通,,代表下层第1个门与上层第一个门不联通,以此类推联通就能够用矩阵表示了。这样改动和查询都能够用线段树来完毕。

    代码:

    #include<iostream>
    #include<sstream>
    #include<map>
    #include<cmath>
    #include<fstream>
    #include<queue>
    #include<vector>
    #include<sstream>
    #include<cstring>
    #include<cstdio>
    #include<stack>
    #include<bitset>
    #include<ctime>
    #include<string>
    #include<cctype>
    #include<iomanip>
    #include<algorithm>
    using namespace std  ;
    #define INT __int64
    #define L(x)  (x * 2)
    #define R(x)  (x * 2 + 1)
    const int INF = 0x3f3f3f3f ;
    const double esp = 0.0000000001 ;
    const double PI = acos(-1.0) ;
    const INT mod =  1000000007 ;
    const int MY = 1400 + 5 ;
    const int MX = 50000 + 5 ;
    int n ,m ;
    struct node
    {
        int le ,rt ;
        INT p[2][2] ;
    }T[MX*8] ;
    node operator *(const node& a ,const node& b)
    {
        node c ;
        memset(c.p ,0 ,sizeof(c.p)) ;
        for(int i = 0 ;i < 2 ; ++i)
          for(int k = 0 ;k < 2 ; ++k)
             if(a.p[i][k])
                for(int j = 0 ;j < 2 ; ++j)
                   c.p[i][j] = (c.p[i][j] + a.p[i][k]*b.p[k][j])%mod ;
        return c ;
    }
    void build(int x ,int le ,int rt)
    {
        T[x].le = le ; T[x].rt = rt ;
        if(le == rt)
        {
            for(int i = 0 ;i < 2 ; ++i)
              for(int j = 0 ;j < 2 ; ++j)
                  T[x].p[i][j] = 1 ;
            return ;
        }
        int Mid = (le + rt)>>1 ;
        build(L(x) ,le ,Mid) ;
        build(R(x) ,Mid+1 ,rt) ;
        T[x] = T[L(x)] * T[R(x)] ;
        T[x].le = le ; T[x].rt = rt ;
    }
    void update(int x ,int pos ,int i ,int j)
    {
        if(T[x].le == T[x].rt)
        {
            T[x].p[i][j] ^= 1 ;
            return ;
        }
        int Mid = (T[x].le + T[x].rt)>>1 ;
        if(pos <= Mid)   update(L(x) ,pos ,i ,j) ;
        else    update(R(x) ,pos ,i ,j) ;
        int le = T[x].le ,rt = T[x].rt ;
        T[x] = T[L(x)] * T[R(x)] ;
        T[x].le = le ; T[x].rt = rt ;
    }
    node section(int x ,int le ,int rt) // 查询
    {
        if(T[x].le == le && T[x].rt == rt)
            return T[x] ;
        int Mid = (T[x].le + T[x].rt)>>1 ;
        if(rt <= Mid)      return   section(L(x) ,le ,rt) ;
        else if(le > Mid)  return   section(R(x) ,le ,rt) ;
        else
              return  section(L(x) ,le ,Mid)*section(R(x) ,Mid+1 ,rt) ;
    }
    int main()
    {
        //freopen("input.txt" ,"r" ,stdin) ;
        int p ,u ,v ,z ;
        while(~scanf("%d%d" ,&n ,&m))
        {
            build(1 ,1 ,n) ;
            for(int i = 0 ;i < m ; ++i)
            {
                scanf("%d" ,&p) ;
                if(p)
                {
                    scanf("%d%d%d" ,&u ,&v ,&z) ;
                    update(1 ,u ,v-1 ,z-1) ;
                }
                else
                {
                   scanf("%d%d" ,&u ,&v) ;
                   node ans = section(1 ,u ,v-1) ;
                   printf("%I64d
    " ,(ans.p[0][0] + ans.p[0][1] + ans.p[1][0] + ans.p[1][1])%mod) ;
                }
            }
        }
        return 0 ;
    }
    
    


    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    oppo手机永久打开USB调试模式
    一个简单的php分页类代码(转载)
    php分页类的二种调用方法(转载)
    直流电与交流电的几点区别
    变压器的分类_变压器的作用
    静态无功补偿与动态无功补偿的区别(转载)
    无功补偿装置三种投切方式(转载)
    西门子plc串口通讯方式
    电动葫芦起吊重物时摇晃怎么办?
    电灯节电小知识的方法大全(转载)
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4820001.html
Copyright © 2020-2023  润新知