<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                題目鏈接:[點擊打開鏈接](http://acm.hdu.edu.cn/showproblem.php?pid=1698) 題意: 輸入一個n表示一段長度為n的區間,有n個編號為1~n的點,初始值全部為1。 有q個操作, 每個操作有3個數:l,r,v表示將區間l~r的所有元素修改為v。 求經過q次修改后的整個區間的值之和。 該題是最典型的線段樹區間修改問題, 需要用到所謂的懶惰標記。 ? 聽起來挺難的,其實非常簡單, 其原理如下: 因為修改很多值, 如果還是按照原來的更新方法, 每個結點更新一次的話,速度實在太慢。 那么能不能一起更新呢? ?答案是肯定的。 一個點一個點的更新之所以慢 , 是因為每個被該點影響的點我們都需要更新。 ? 為了能”順便“更新, 我們在每個結點上多維護一個信息, 表示上次該區間修改的值是多少,然后然后每次向下更新之前將標記更新到兒子結點。 對于線段樹, 只要理解好每個結點表示一個不重復不交叉的區間, 就差不多可以理解其更新過程了。 細節參見代碼: ~~~ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) using namespace std; typedef long long ll; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 1000000000; const int maxn = 100000 + 10; int T,n,l,r,v,q,sum[maxn*4],cur[maxn*4],kase=0; void push_up(int o) { sum[o] = sum[o<<1] + sum[o<<1|1]; } void pushdown(int o, int l, int r) { if(cur[o]) { int m = (l + r) >> 1; cur[o<<1] = cur[o<<1|1] = cur[o]; sum[o<<1] = (m - l + 1) * cur[o]; sum[o<<1|1] = (r - m) * cur[o]; cur[o] = 0; } } void build(int l, int r, int o) { int m = (l + r) >> 1; cur[o] = 0; if(l == r) { sum[o] = 1; return ; } build(l, m, o<<1); build(m+1, r, o<<1|1); push_up(o); } void update(int L, int R, int c, int l, int r, int o) { int m = (l + r) >> 1; if(L <= l && r <= R) { cur[o] = c; sum[o] = c * (r - l + 1); return ; } pushdown(o, l, r); if(L <= m) update(L, R, c, l, m, o<<1); if(m < R) update(L, R, c, m+1, r, o<<1|1); push_up(o); } int main() { scanf("%d",&T); while(T--) { scanf("%d%d",&n,&q); build(1,n,1); while(q--) { scanf("%d%d%d",&l,&r,&v); update(l, r, v, 1, n, 1); } printf("Case %d: The total value of the hook is %d.\n",++kase , sum[1]); } return 0; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看