<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      書山有徑勤為路>>>>>>>>

      <<<<<<<<學(xué)海無涯苦作舟!

      線段樹和下移操作解決HDOJ 1698

       

       

      Problem Description
      In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which
      are of the same length.



      Now Pudge wants to do some operations on the hook.

      Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y,
      into cupreous sticks, silver sticks or golden sticks.
      The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:

      For each cupreous stick, the value is 1.
      For each silver stick, the value is 2.
      For each golden stick, the value is 3.

      Pudge wants to know the total value of the hook after performing the operations.
      You may consider the original hook is made up of cupreous sticks.
       

       

      Input
      The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
      For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
      Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
       

       

      Output
      For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
       

       

      Sample Input
      1
      10
      2
      1 5 2
      5 9 3
       

       

      Sample Output
      Case 1: The total value of the hook is 24.
       
       
       
      這道題目的關(guān)鍵就是求整個區(qū)間的和了,其它的都好說。
      如何求和呢,這里用到了一個技巧,也就是將無效區(qū)間段
      的value域全部置0,并將其value向下移動,然后將有效
      區(qū)間段的value累加起來就可以 了。話說如何置0呢?
      如何下移呢?且看代碼中的注釋!
       
      View Code
      #include "iostream"
      using namespace std;
      struct Node
      {
      int left;
      int right;
      int mid;
      int value;
      };
      Node Tree[300000];
      void BuildTree(int level, int left, int right)
      {
      Tree[level].value = 1;
      Tree[level].left = left;
      Tree[level].right = right;
      Tree[level].mid = (left+right)/2;
      if(left==right)
      return;
      else
      {
      BuildTree(2*level, left, Tree[level].mid);
      BuildTree(2*level+1, Tree[level].mid+1, right);
      }
      }
      void Insert(int level, int left, int right, int value)
      {
      if(left==Tree[level].left && right==Tree[level].right)
      {
      Tree[level].value = value;
      return;
      }
      if(Tree[level].value != 0) //這個if語句的作用就是將value下移,并將無效的區(qū)間段置0
      {
      Tree[2*level].value = Tree[level].value;
      Tree[2*level+1].value = Tree[level].value;
      Tree[level].value = 0;
      }
      if(left > Tree[level].mid)
      Insert(2*level+1, left, right, value);
      else if(right <= Tree[level].mid)
      Insert(2*level, left, right, value);
      else
      {
      Insert(2*level, left, Tree[level].mid, value);
      Insert(2*level+1, Tree[level].mid+1, right, value);
      }
      }
      int SumUp(int level, int left, int right)
      {
      if(Tree[level].value > 0)
      {
      //cout<<" "<<Tree[level].left<<" "<<Tree[level].right<<" "<<Tree[level].value<<endl;
      //上面這個句子用來看看哪些是有效的區(qū)間段
      return Tree[level].value*(Tree[level].right-Tree[level].left+1);
      }
      if(left > Tree[level].mid)
      SumUp(2*level+1, left, right);
      else if(right <= Tree[level].mid)
      SumUp(2*level, left, right);
      else
      return SumUp(2*level, left, Tree[level].mid)+SumUp(2*level+1, Tree[level].mid, right);
      //累加的功能是在上面的這個return語句實現(xiàn)的,這個就是遞歸的妙處了。
      }
      int main()
      {
      int Case, lenofline, numofoper, left, right, value;
      while(cin>>Case)
      {
      for(int i=1; i<=Case; i++)
      {
      cin>>lenofline>>numofoper;
      BuildTree(1, 1, lenofline);
      while(numofoper--)
      {
      cin>>left>>right>>value;
      Insert(1, left, right, value);
      }
      cout<<"Case "<<i<<": The total value of the hook is "<<SumUp(1, 1, lenofline)<<"."<<endl;
      }
      }
      }

      Find函數(shù)的另外一種寫法,用來統(tǒng)計經(jīng)過點的所有次數(shù)
      int Find(int level, int target)
      {
      if(target==Tree[level].left && target==Tree[level].right)
      return Tree[level].icount;
      else if(target > Tree[level].mid)
      return Tree[levle].icount+Find(2*level+1, target);
      else if(target <= Tree[level].mid)
      return Tree[level].icount+Find(2*level, target);
      }


      posted on 2011-10-02 10:22  More study needed.  閱讀(318)  評論(0)    收藏  舉報

      導(dǎo)航

      書山有徑勤為路>>>>>>>>

      <<<<<<<<學(xué)海無涯苦作舟!

      主站蜘蛛池模板: 亚洲一区二区三区水蜜桃| 无限看片在线版免费视频大全 | 日韩精品av一区二区三区| 久久精品国产99国产精品严洲| 97久久久精品综合88久久| 国产一级三级三级在线视| 星座| 九九热在线视频免费观看| 亚洲综合成人av在线| 好了av四色综合无码| 制服 丝袜 亚洲 中文 综合| 亚洲一级特黄大片一级特黄| 亚洲成A人片在线观看的电影| 131mm少妇做爰视频| 亚洲a片无码一区二区蜜桃| 四虎国产精品永久入口| 免费无码又爽又刺激网站| 黄色国产精品一区二区三区| 国产精品一二三区蜜臀av| 一出一进一爽一粗一大视频| 国产精品白浆免费视频| 福利网午夜视频一区二区| 波多野结衣av一区二区三区中文| 精品国产中文字幕在线看| 亚洲更新最快无码视频| аⅴ天堂中文在线网| 国产伦码精品一区二区| 玛曲县| 成人午夜在线观看日韩| 丰满少妇被猛烈进出69影院| L日韩欧美看国产日韩欧美| 色老头亚洲成人免费影院| 国产片一区二区三区视频| 无码吃奶揉捏奶头高潮视频| 成人一区二区三区激情视频| 人妻中出无码中字在线| 成人av午夜在线观看| 在线观看国产成人av天堂| 亚洲欧洲中文日韩久久av乱码| 国产av国片精品一区二区| 92国产精品午夜福利免费|