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. 十年阿里架构师教你如何一举拿下阿里的Offer,(附面试技巧)

    前言: 现在很多人即将毕业或者换工作面临找工作,为了帮助大家,遂写下这篇文章.如果你想进入BAT,抑或拿到高工资,无论你的基础如何,你至少要花三个月时间来准备简历.笔试题.面试题.对于没有项目经验,没 ...

  2. LVM——header

  3. Ubuntu系统---NVIDIA 驱动安装

    Ubuntu系统---NVIDIA 驱动安装 第一次安装“NVIDIA 驱动”,小小的激动,因为终于可以玩GPU了.预想一块GPU,盼望太久,差点放弃,感谢J姐让我捡个漏.但是,第一次新的试错过程,网 ...

  4. 基于 Go 的可嵌入脚本语言 zygomys

    zygomys zygomys 是一种可嵌入的脚本语言. 它是一个具有面向对象风格的现代化 Lisp,提供了一个解释器和 REPL(Read-Eval-Print-Loop:也就是说,它带有一个命令行 ...

  5. 添加索引:BLOB/TEXT column 'xxx' used in key specification without a key length

    问题 1. 将DataFrame数据保存到mysql后,添加索引出现错误提示: BLOB/TEXT column used in key specification without a key len ...

  6. springboot2.0入门(八)-- profile启动文件配置

    一.不同环境使用不同配置文件 将application.yml文件拷贝三份,在文件末尾分别对应开发/生产/测试,dev/prod/test/文件夹,其中application.yml 中默认激活开发环 ...

  7. MySQL中的连接、实例、会话、数据库、线程之间的关系

    MySQL中的实例.数据库关系简介 1.MySQL是单进程多线程(而Oracle等是多进程),也就是说MySQL实例在系 统上表现就是一个服务进程,即进程(通过多种方法可以创建多实例,再安装一个端口号 ...

  8. final详解

    final的含义? final:java中的关键字,意为“终态的”或者“无法改变的”.可用来修饰类.变量.方法. 变量(成员变量.静态变量.局部变量) 注意: 1.final变量即为常量,通常常量名大 ...

  9. paramiko获取主机信息

    import re import paramiko host="192.168.4.88" user = "root" password = " cl ...

  10. MongoDB 运维实总结

    一.MongoDB 集群简介 MongoDB是一个基于分布式文件存储的数据库,其目的在于为WEB应用提供可扩展的高性能数据存储解决方案.下面将以3台机器介绍最常见的集群方案.具体介绍,可以查看官网 h ...