
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderA - Correcting the Household Account Book【题目描述】Takahashi is keeping a household account book forN NNdays.Takahashi’s account balance is initially0 00yen. On dayi ii( 1 ≤ i ≤ N ) (1 \leq i \leq N)(1≤i≤N), a transaction ofA i A_iAiyen is recorded, where a positive value represents a deposit and a negative value represents a withdrawal. Each day’s transaction is applied to the account balance in order (the account balance may become negative during the process). The account balance at the end of dayN NN, after all transactions have been applied, isA 1 A 2 ⋯ A N A_1 A_2 \cdots A_NA1A2⋯ANyen.However, while reviewing the account book, Takahashi noticed that some transactions were recorded incorrectly. He then performsQ QQcorrection operations in order. In thej jj-th operation( 1 ≤ j ≤ Q ) (1 \leq j \leq Q)(1≤j≤Q), he changes the transaction amount on dayD j D_jDjto0 00yen. Once a day’s transaction amount has been changed to0 00, it remains0 00in all subsequent operations. In other words, with each operation, the number of days whose transaction amounts have been set to0 00increases.After each operation, find the sum of all days’ transaction amounts, that is, the account balance at the end of dayN NN.Note thatD 1 , D 2 , … , D Q D_1, D_2, \ldots, D_QD1,D2,…,DQare all distinct. In other words, the same day’s transaction amount is never changed more than once.高桥正在记录一本为期N NN天的家庭账簿。高桥的账户余额初始为0 00日元。在第i ii天1 ≤ i ≤ N 1 \leq i \leq N1≤i≤N记录了一笔金额为A i A_iAi日元的交易其中正值表示存款负值表示取款。每天的交易按顺序应用到账户余额上过程中账户余额可能变为负数。在第N NN天结束时所有交易应用后的账户余额为A 1 A 2 ⋯ A N A_1 A_2 \cdots A_NA1A2⋯AN日元。然而在复核账簿时高桥注意到一些交易记录有误。于是他按顺序执行Q QQ次更正操作。在第j jj次操作1 ≤ j ≤ Q 1 \leq j \leq Q1≤j≤Q中他将第D j D_jDj天的交易金额更改为0 00日元。一旦某天的交易金额被更改为0 00它在所有后续操作中都将保持为0 00。换句话说每次操作后交易金额被设为0 00的天数会增加。每次操作后求所有天数的交易金额之和即第N NN天结束时的账户余额。注意D 1 , D 2 , … , D Q D_1, D_2, \ldots, D_QD1,D2,…,DQ互不相同。也就是说同一天的交易金额不会被更改超过一次。【输入】N NNQ QQA 1 A_1A1A 2 A_2A2⋯ \cdots⋯A N A_NAND 1 D_1D1D 2 D_2D2⋮ \vdots⋮D Q D_QDQThe first line contains an integerN NNrepresenting the number of days in the account book and an integerQ QQrepresenting the number of correction operations, separated by a space.The second line containsN NNintegersA 1 , A 2 , … , A N A_1, A_2, \ldots, A_NA1,A2,…,ANrepresenting the transaction amounts for each day, separated by spaces.A i A_iAiis the transaction amount on dayi ii.Among the followingQ QQlines, thej jj-th line (the( 2 j ) (2 j)(2j)-th line overall) contains a single integerD j D_jDjrepresenting the day whose transaction amount is changed to0 00in thej jj-th operation.【输出】PrintQ QQlines. On thej jj-th line, print the sum of all days’ transaction amounts (the account balance at the end of dayN NN) after performing all operations from the1 11-st through thej jj-th.【输入样例】5 3 100 -50 200 -30 80 2 4 1【输出样例】350 380 280【算法标签】#模拟【代码详解】#includebits/stdc.husingnamespacestd;// 定义长整型别名便于处理大数据#defineintlonglong// 定义数组最大容量constintN200005;// 全局变量声明intn;// 数组长度intq;// 查询次数inta[N];// 存储原始数组元素// 主函数入口使用signed避免与long long冲突signedmain(){// 读取数组长度和查询次数cinnq;// 计算所有元素的总和intsum0;for(inti1;in;i){cina[i];suma[i];// 累加每个元素到总和}// 处理每个查询while(q--){intx;// 要删除的元素下标cinx;sum-a[x];// 从总和中减去该元素coutsumendl;// 输出剩余元素的和}return0;}【运行结果】5 3 100 -50 200 -30 80 2 350 4 380 1 280