We have an array A of integers, and an array queries of queries.

For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index].  Then, the answer to the i-th query is the sum of the even values of A.

(Here, the given index = queries[i][1] is a 0-based index, and each query permanently modifies the array A.)

Return the answer to all queries.  Your answer array should have answer[i] as the answer to the i-th query.

class Solution {
public:
vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) {
int initval = ;
vector<int> ret;
for(int v : A) {
if(v % == ) initval += v;
}
for(auto v : queries) {
int before = A[v[]];
A[v[]] += v[];
if(before % == ) initval -= before;
if(A[v[]] % == ) initval += A[v[]];
ret.push_back(initval);
}
return ret;
}
};

LC 985. Sum of Even Numbers After Queries的更多相关文章

  1. 【LEETCODE】47、985. Sum of Even Numbers After Queries

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  2. 【Leetcode_easy】985. Sum of Even Numbers After Queries

    problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAft ...

  3. [Solution] 985. Sum of Even Numbers After Queries

    Difficulty: Easy Question We have an array A of integers, and an array queries of queries. For the i ...

  4. 985. Sum of Even Numbers After Queries

    We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i] ...

  5. #Leetcode# 985. Sum of Even Numbers After Queries

    https://leetcode.com/problems/sum-of-even-numbers-after-queries/ We have an array A of integers, and ...

  6. LeetCode 985 Sum of Even Numbers After Queries 解题报告

    题目要求 We have an array A of integers, and an array queries of queries. For the i-th query val = queri ...

  7. 【leetcode】985. Sum of Even Numbers After Queries

    题目如下: We have an array A of integers, and an array queries of queries. For the i-th query val = quer ...

  8. 【LeetCode】985. Sum of Even Numbers After Queries 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找规律 日期 题目地址:https://lee ...

  9. LeetCode.985-查询后偶数的总和(Sum of Even Numbers After Queries)

    这是悦乐书的第370次更新,第398篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第232题(顺位题号是985).有一个整数数组A和一个查询数组queries. 对于第i ...

随机推荐

  1. 为什么Java大数据能带你走上人生巅峰

    国内大多数大型互联网公司的程序员被称作研发工程师,但实际上国内几乎没有研发项目,只能叫做开发. 开发程序员的工作大多是重复性劳动,容易产生疲惫感,薪资在工作2-5年内就达到了一个峰值,再要提升就比较困 ...

  2. MySQL数据库---数据库管理

    -- 创建用户,指定明文密码create user 'rose'@'localhost' identified by 'rosepwd'; -- 查看用户是否创建成功select user,host ...

  3. MySQL学习笔记-MHA安装配置

    一.配置主从同步   1. 本例中主从ip及端口 Master:10.1.5.8:3306 Slave1:10.1.5.9:3306 (候选master) Slave2:10.1.5.195:3306 ...

  4. ORA-3136 问题处理

    Alert 日志报错: Wed May :: *********************************************************************** Fatal ...

  5. MySQL之Text Protocol

    1)[01]COM_QUIT 告诉服务器,客户端想要关闭连接 返回:或者关闭一个连接或者一个OK_Packet 有效负载: 1 [01]COM_QUIT 字段: command(1)--0x01 CO ...

  6. 我是怎么找到电子书的 - IT篇

    转自于:http://my.oschina.net/0757/blog/375908#OSC_h2_8 IT-ebooks http://it-ebooks.info/ http://www.it-e ...

  7. [转]python3 跨目录模块调用,你真的懂了吗?

    小伙伴们,你们有遇到过调用自己写的模块(跨目录模块调用),提示你ImportError:No module named ...的情况,如果有,而且到现在还没有搞明白的,我想说,你今天看对文章了. 这篇 ...

  8. Hadoop动态增加节点与删除节点

    Hadoop的全分布式安装网上也很多教程,踩过很多坑,整理不出来了……赶紧把增加删除节点留住. 均衡数据 (1)设置数据传输带宽为64M(默认值比较低) hdfs dfsadmin -setBalan ...

  9. - The superclass "javax.servlet.http.HttpServlet" was not found on the Java

    网上有很多解决方法,如这种 下面是具体的解决方法:1.右击web工程->属性或Build Path->Java Build Path->Libraries-> Add Libr ...

  10. nginx+uwsgi+bottle python服务器部署

    一.安装nginx(如果服务器上已经有nginx了,则无需重复安装) sudo apt-get install nginx 二.nginx配置,例如:/etc/nginx/conf.d/digger. ...