OJ Problem Set - 3745

Salary Increasing


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 n integers 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 ≤ liri ≤ 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}.


Author: CHEN, Weijie

Contest: ZOJ Monthly, December 2013

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int maxn=+;
int num[maxn];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,q;
while(~scanf("%d%d",&n,&q))
{
int tmp;
ll sum=;
memset(num,,sizeof(num));
for(int i=;i<n;++i)
{
scanf("%d",&tmp);
num[tmp]++;
sum+=tmp;
}
int l,r,c;
while(q--)
{
scanf("%d%d%d",&l,&r,&c);
//if(l>r) swap(l,r);
for(int i=r;i>=l;--i)
{
sum+=(ll)c*num[i];
if(i+c<maxn) num[i+c]+=num[i];
num[i]=;
}
}
printf("%lld\n",sum);
}
return ;
}

zoj3745 Salary Increasing的更多相关文章

  1. ZOJ 3745 Salary Increasing

    Description Edward has established a company with n staffs. He is such a kind man that he did Q time ...

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

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

  3. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  4. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  5. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  6. [LeetCode] Department Highest Salary 系里最高薪水

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

  7. [LeetCode] Nth Highest Salary 第N高薪水

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  8. [LeetCode] Second Highest Salary 第二高薪水

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  9. git error: unable to rewind rpc post data - try increasing http.postBuffer

    error: unable to rewind rpc post data - try increasing http.postBuffererror: RPC failed; curl 56 Rec ...

随机推荐

  1. Memcached——非关系型数据库分布式处理

    Memcached登录校验应用: MMCacheWriter.cs类 using Memcached.ClientLibrary; using System; using System.Collect ...

  2. 小心as"陷阱"(c#)

    有一种情况,使用as编译时没错,运行时也没错,但是结果错了. object a=1; string b=a as String; 由于a是objecy类型,是引用类型,所以可以用as转换,但是实际上b ...

  3. Chrome的Crash Report服务

    <本文转自:http://www.cppblog.com/woaidongmao/archive/2009/10/22/99211.aspx> 本文翻译自debugInfo网站上一篇文章g ...

  4. git使用问题汇总

    2015.11.29 一.git clone 出现如下问题: 解决方案:添加一个ssh keys.步骤如下: 1.生成一个ssh-key(图片来自网络) 2.找到“Your identificatio ...

  5. oracle-1

    使用sqlplus 进入oracle (1)服务的启动终止 oracle 服务的关闭: SQL> shutdown immediate; oracle服务的启动: SQL> startup ...

  6. PHP ADLogin

    <?php $user = 'aaaa'; $password = 'xxxx'; $domain = 'b.a.com'; //设定域名 $port = 3268; $basedn = 'dc ...

  7. [转]DIV+CSS和TABLE的区别

    现在全国大大小小的网站都在搞一场技术“革命”,就是所谓“网站重构”说简单点就是DIV+CSS进行网站制作.用DIV+CSS代替传统的Table制作框架和美化页面.百度搜索优化 在重构之前,肯定要了解为 ...

  8. 加载数据库驱动程序的方法和JDBC的流程

    加载驱动方法 1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2. DriverManager.r ...

  9. 【前端学习】sublime开启vim模式

    学习目标:在sublime下开启vim模式,了解基本vim的编辑快捷键. 下载安装Sublime Text 3 :http://www.sublimetext.com/3 Vim/Vi: Vim/Vi ...

  10. CVE-2014-0160 Heartbleed Vul Analysis && OpenSSL Cryptographic Software Library Bug

    目录 . Heartbleed漏洞简介 . 漏洞造成的风险和影响 . 漏洞的测试.POC . OpenSSL漏洞源代码分析 . 防御.修复方案 . 从漏洞中得到的攻防思考 1. Heartbleed漏 ...