第一版有7个时间超限,优化成了第二版:

1:

#!/bin/python3

import math
import os
import random
import re
import sys # Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
# n is lenth m is operatation
m = len(queries)
arr = [0]*n
for i in range(m):
start = queries[i][0]
end = queries[i][1]
for j in range (start -1, end):
arr[j] += queries[i][2]
return max(arr)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w') nm = input().split() n = int(nm[0]) m = int(nm[1]) queries = [] for _ in range(m):
queries.append(list(map(int, input().rstrip().split()))) result = arrayManipulation(n, queries) fptr.write(str(result) + '\n') fptr.close()

2:

#!/bin/python3

import math
import os
import random
import re
import sys # Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
# n is lenth m is operatation
m = len(queries)
arr = [0]*(n+1)
for i in range(m):
start = queries[i][0]
end = queries[i][1]
arr[start - 1] += queries[i][2]
if (end <=len(arr)):
arr[end] -= queries[i][2] max =x =0
for i in arr:
x = x + i
if (max < x) : max =x
return max
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w') nm = input().split() n = int(nm[0]) m = int(nm[1]) queries = [] for _ in range(m):
queries.append(list(map(int, input().rstrip().split()))) result = arrayManipulation(n, queries) fptr.write(str(result) + '\n') fptr.close()

HR_Array Manipulation的更多相关文章

  1. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  2. Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体旋转)

    Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...

  3. Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体平移)

    Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...

  4. Track files and folders manipulation in Windows

    The scenario is about Business Secret and our client do worry about data leakage. They want to know ...

  5. Data manipulation primitives in R and Python

    Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...

  6. VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...

  7. Bash String Manipulation Examples – Length, Substring, Find and Replace--reference

    In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...

  8. windows phone 之手势识别(Manipulation)

    在Windows Phone 7的多触摸屏上可以检测到至少四根同时存在的手指,并且一起操作使触摸屏充分发挥效果. 在silverlight开发中通过事件来实现触屏事件的检测,包括低级别的和高级别的接口 ...

  9. WPF Multi-Touch 开发:高级触屏操作(Manipulation)

    原文 WPF Multi-Touch 开发:高级触屏操作(Manipulation) 在上一篇中我们对基础触控操作有了初步了解,本篇将继续介绍触碰控制的高级操作(Manipulation),在高级操作 ...

随机推荐

  1. Memcached 集群架构与memcached-session-manager

    Memcached 集群架构方面的问题_知识库_博客园https://kb.cnblogs.com/page/69074/ memcached-session-manager配置 - 学习中间件调优管 ...

  2. Linux启动/停止/重启Mysql数据库

    1.查看mysql版本 1)status; 2)select version(); 2.Mysql启动 1)使用 service 启动: service mysqld start (5.0版本是mys ...

  3. hive排序

    1.升序排序 hive > select  id,name,sal from emp order by sal; 2.降序  添加关键字desc hive > select  id,nam ...

  4. MySQL系列:视图基本操作(3)

    1. 视图简介 1.1 视图定义 视图是一种虚拟的表,是从数据库中一个或多个表中导出来的表. 视图可以从已存在的视图的基础上定义. 数据库中只存放视图的定义,并没有存放视图中的数据,数据存放在原来的表 ...

  5. python设计模式第二十二天【备忘录模式】

    1.应用场景 (1)能保存对象的状态,并能够恢复到之前的状态 2.代码实现 #!/usr/bin/env python #! _*_ coding:UTF-8 _*_ class Originator ...

  6. js对json解析获取对应属性的值,JSON.stringify()和JSON.parse()

    JSON.stringify() 该方法,将一个JSON对象转化为字符串string JSON.parse() 该方法,将一个字符串转化为JSON对象object 对于JSON对象,获取其对应键值 可 ...

  7. UML符号

    转抄, 语言简练. 挺好. -------------------  -------------------  -------------------  -------------------  -- ...

  8. 日历插件bootstrap-datetimepicker的使用感悟

    首先队长先综述一下插件的使用三步流程:即 1.引入插件  2.使用jquery选择器选择目标标签  3.对目标标签绑定插件函数来触发插件 雷同于python中的库的使用(安装库 导入库 引用库) 下面 ...

  9. 导出数据到EXL表格中

    项目使用的是SSI框架,通过struts访问到action xml文件: <action name="fabAttributedaochu" class="com. ...

  10. 解析xml文件 selectSingleNode取不到节点

    今天在做批量生成XML的时候,碰到一个情况 解析xml文件 selectSingleNode一直返回NULL. XML的格式开头有一句这个<CE401Message xmlns="ht ...