ZOJ 3745 Salary Increasing

來源:互聯網
上載者:User

標籤:

Description

Edward has established a company with n staffs. He is such a kind man that he did Q times salary increasing for his staffs. Each salary increasing was described by three integers (l, r, c). That means Edward will add c units money for the staff whose salaxy is in range [l, r] now. Edward wants to know the amount of total money he should pay to staffs after Q times salary increasing.

Input

The input file contains multiple test cases.

Each case begin with two integers : n -- which indicate the amount of staff; Q -- which indicate Q times salary increasing. The following nintegers each describes the initial salary of a staff(mark as ai). After that, there are Q triples of integers (li, ri, ci) (i=1..Q) which describe the salary increasing in chronological.

1 ≤ n ≤ 105 , 1 ≤ Q ≤ 105 , 1 ≤ ai ≤ 105 , 1 ≤ li ≤ ri ≤ 105 , 1 ≤ ci ≤ 105 , ri < li+1

Process to the End Of File.

Output

Output the total salary in a line for each case.

Sample Input

4 11 2 3 42 3 4

Sample Output

18
Hint

{1, 2, 3, 4} → {1, 4, 6, 7}.

 

這絕對是個水題,但同時又是個不折不扣的大坑題,一開始沒注意ri < li+1 ,差點用線段樹做。

 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4  5 long long num[600100],n,m,l,r,add;//坑!開100005不夠,因為工資一開始最高為100000,但後面可以漲工資。  6 int main() 7 { 8      9     while (cin>>n>>m)10     {11           memset(num,0,sizeof(num));12           for (int i=1;i<=n;i++)13           {14               cin>>add;15               num[add]++;16           }17           for (int i=1;i<=m;i++)18           {19               cin>>l>>r>>add;20               for (int j=r;j>=l;j--)//坑!應該從大到小計算,不然會對後面產生影響。 21               {22                   if (num[j])23                   {24                              num[j+add]+=num[j];25                              num[j]=0;26                   }27               }28           }29           add=0;30           for (int i=1;i<600100;i++)//坑!一開始只從1算到100000,wrong了好幾次,後來發現工資可能超過100000. 31               add=add+num[i]*i;32           cout <<add<<endl;33     }34     return 0;35 }
View Code

 

#include <iostream>#include <cstring>using namespace std;
long long num[600100],n,m,l,r,add;//坑!開100005不夠,因為工資一開始最高為100000,但後面可以漲工資。 int main(){        while (cin>>n>>m)    {          memset(num,0,sizeof(num));          for (int i=1;i<=n;i++)          {              cin>>add;              num[add]++;          }          for (int i=1;i<=m;i++)          {              cin>>l>>r>>add;              for (int j=r;j>=l;j--)//坑!應該從大到小計算,不然會對後面產生影響。               {                  if (num[j])                  {                             num[j+add]+=num[j];                             num[j]=0;                  }              }          }          add=0;          for (int i=1;i<600100;i++)//坑!一開始只從1算到100000,wrong了好幾次,後來發現工資可能超過100000.               add=add+num[i]*i;          cout <<add<<endl;    }    return 0;}

 

ZOJ 3745 Salary Increasing

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.