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 (lrc). That means Edward will add c units money for the staff whose salaxy is in range [lr] 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 (lirici) (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 1
1 2 3 4
2 3 4

Sample Output

18

Hint

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

这绝对是个水题,但同时又是个不折不扣的大坑题,一开始没注意ri < li+1 ,差点用线段树做。

 #include <iostream>
#include <cstring>
using namespace std; long long num[],n,m,l,r,add;//坑!开100005不够,因为工资一开始最高为100000,但后面可以涨工资。
int main()
{ while (cin>>n>>m)
{
memset(num,,sizeof(num));
for (int i=;i<=n;i++)
{
cin>>add;
num[add]++;
}
for (int i=;i<=m;i++)
{
cin>>l>>r>>add;
for (int j=r;j>=l;j--)//坑!应该从大到小计算,不然会对后面产生影响。
{
if (num[j])
{
num[j+add]+=num[j];
num[j]=;
}
}
}
add=;
for (int i=;i<;i++)//坑!一开始只从1算到100000,wrong了好几次,后来发现工资可能超过100000.
add=add+num[i]*i;
cout <<add<<endl;
}
return ;
}

#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的更多相关文章

  1. zoj 3745 Salary Increasing(坑爹的细节题!)

    题目 注意题目中的,引用绝望的乐园中的进一步解释如下: 这是一道浙大月赛的题,一如既往的坑爹,好好一道水题,被搞成一道坑题!!! //注意:r(i) < l(i+1) !细节啊细节! #incl ...

  2. zoj3745 Salary Increasing

    OJ Problem Set - 3745 Salary Increasing Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has ...

  3. ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)

    Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  4. $ZOJ\ 2432\ Greatest\ Common\ Increasing\ Subsequence$

    传送门 $Description$ 求两个序列的最长公共上升子序列 $Solution$ $f[i][j]$表示$a$序列匹配到$i$和$b$序列匹配到$j$的最长上升序列的长度,这里并不要求$a[i ...

  5. HDU 1423 Greatest Common Increasing Subsequence LCIS

    题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...

  8. HDU1423:Greatest Common Increasing Subsequence(LICS)

    Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...

  9. Greatest Common Increasing Subsequence hdu1423

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

随机推荐

  1. C#编程实现朴素贝叶斯算法下的情感分析

    C#编程实现 这篇文章做了什么 朴素贝叶斯算法是机器学习中非常重要的分类算法,用途十分广泛,如垃圾邮件处理等.而情感分析(Sentiment Analysis)是自然语言处理(Natural Lang ...

  2. MVC入门之.Net语法学习

    本节中主要学习.Net框架性语法.开发者可以使用新语法提高编程的效率以及代码的运行效率:其本质都是“语法糖”,由编译器在编译时转成原始语法. u  自动属性 Auto-Implemented Prop ...

  3. 域控制器安全策略在哪里 Windows server 2008

    Start(开始)–Programs(程序)–Administrative Tools(管理工具)–Group Policy Management(策略管理器) 展开组策略管理器选择–Forest(林 ...

  4. ACM1174_爆头解题思路_空间三维坐标求点到直线的距离

    /* 爆头 Description gameboy是一个CS高手,他最喜欢的就是扮演警察, 手持M4爆土匪的头.也许这里有人没玩过CS,有必 要介绍一下“爆头”这个术语:所谓爆头,就是子 弹直接命中对 ...

  5. 算法的稳定性(Stability of Sorting Algorithms)

    如果具有同样关键字的纪录的在排序前和排序后相对位置保持不变.一些算法本身就是稳定的,如插入排序,归并排序,冒泡排序等,不稳定的算法有堆排序,快速排序等. 然而,一个本身不稳定的算法通过一点修正也能变成 ...

  6. Zoj3332-Strange Country II(有向竞赛图)

    You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...

  7. Oracle判断语句集合(转载)

    SELECT decode(sign(to_date('2008-05-01', 'yyyy-MM-dd') -                   to_date('2008-03-01', 'yy ...

  8. 04747_Java语言程序设计(一)_第7章_图形、图像与多媒体

    例7.1小应用程序用6种字型显示字符串,显示内容说明本身的字型. import java.applet.*; import java.awt.*; public class Example7_1 ex ...

  9. functools:管理函数工具(部分)

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #functools:管理函数工具 #作用:处理其他函数的函数 #版 ...

  10. codeforces 166C Median - from lanshui_Yang

    C. Median time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...