链接:

https://vjudge.net/problem/Gym-100741A

题意:

Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my friend, a mathematician, thinks that it is very fun to play with a sequence of integer numbers. He writes the sequence in a row. If he wants he increases one number of the sequence, sometimes it is more interesting to decrease it (do you know why?..) And he likes to add the numbers in the interval [l;r]. But showing that he is really cool he adds only numbers which are equal some mod (modulo m).

Guess what he asked me, when he knew that I am a programmer? Yep, indeed, he asked me to write a program which could process these queries (n is the length of the sequence):

  • p r It increases the number with index p by r. (, )

    You have to output the number after the increase.
  • p r It decreases the number with index p by r. (, ) You must not decrease the number if it would become negative.

    You have to output the number after the decrease.

s l r mod You have to output the sum of numbers in the interval which are equal mod (modulo m). () ()

思路:

看半天没看懂题.

建10个树状数组即可, 对模m的每种情况分别统计.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e4+10;
LL A[MAXN], C[15][MAXN];
int n, m, q; int Lowbit(int x)
{
return x&(-x);
} void Add(int pos, int mod, LL val)
{
while (pos <= n)
{
C[mod][pos] += val;
pos += Lowbit(pos);
}
} LL Query(int pos, int mod)
{
LL ans = 0;
while (pos > 0)
{
ans += C[mod][pos];
pos -= Lowbit(pos);
}
return ans;
} int main()
{
scanf("%d%d", &n, &m);
for (int i = 1;i <= n;i++)
{
scanf("%lld", &A[i]);
Add(i, A[i]%m, A[i]);
}
scanf("%d", &q);
char opt[5];
int l, r, mod;
while (q--)
{
scanf("%s", opt);
if (opt[0] == 's')
{
scanf("%d%d%d", &l, &r, &mod);
printf("%lld\n", Query(r, mod)-Query(l-1, mod));
}
else if (opt[0] == '+')
{
scanf("%d%d", &l, &r);
Add(l, A[l]%m, -A[l]);
A[l] += r;
Add(l, A[l]%m, A[l]);
printf("%lld\n", A[l]);
}
else
{
scanf("%d%d", &l, &r);
Add(l, A[l]%m, -A[l]);
if (r <= A[l])
A[l] -= r;
Add(l, A[l]%m, A[l]);
printf("%lld\n", A[l]);
}
} return 0;
}

Gym-10071A-Queries(树状数组)的更多相关文章

  1. GYM 100741A Queries(树状数组)

    A. Queries time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input ...

  2. Codeforces 369E Valera and Queries --树状数组+离线操作

    题意:给一些线段,然后给m个查询,每次查询都给出一些点,问有多少条线段包含这个点集中的一个或多个点 解法:直接离线以点为基准和以线段为基准都不好处理,“正难则反”,我们试着求有多少线段是不包含某个查询 ...

  3. Gym - 101755G Underpalindromity (树状数组)

    Let us call underpalindromity of array b of length k the minimal number of times one need to increme ...

  4. CF Gym 100463A (树状数组求逆序数)

    题意:给你一个序列,和标准序列连线,求交点数. 题解:就是求逆序对个数,用树状数组优化就行了.具体过程就是按照顺序往树状数组了插点(根据点的大小),因为第i大的点应该排在第i位,插进去的时候他前面本该 ...

  5. Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理

    题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...

  6. GYM 101889F(树状数组)

    bit扫描坐标套路题,注意有重复的点,莽WA了. const int maxn = 1e5 + 5; struct node { ll B, F, D; bool operator < (con ...

  7. gym 100589A queries on the Tree 树状数组 + 分块

    题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数 ...

  8. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  9. Gym 101908C - Pizza Cutter - [树状数组]

    题目链接:https://codeforces.com/gym/101908/problem/C 题意: 一块正方形披萨,有 $H$ 刀是横切的,$V$ 刀是竖切的,不存在大于等于三条直线交于一点.求 ...

  10. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

随机推荐

  1. 登录进入Mysql数据库的几种方式

    前提:连接进入mysql数据库 本机安装的myslq基础信息: host= "localhost", # 数据库主机地址:127.0.0.1 port=3306, # 端口号 us ...

  2. react正常显示html代码、dangerousSetInnerHTML 笔记

    const html =`<h1>今天天色很好</h1>` <div dangerouslySetInnerHTML={{__html:html}}></di ...

  3. PTA(Advanced Level)1011.World Cup Betting

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. [转帖]全方位掌握OpenStack技术知识

    全方位掌握OpenStack技术知识 http://www.itpub.net/2019/06/17/2206/ 架构师技术联盟的文章 相当好呢. 大家好,我是小枣君.最近几年,OpenStack这个 ...

  5. 如何使用JavaScript实现前端导入和导出excel文件

    一.SpreadJS 简介 SpreadJS 是一款基于 HTML5 的纯 JavaScript 电子表格和网格功能控件,以“高速低耗.纯前端.零依赖”为产品特色,可嵌入任何操作系统,同时满足 .NE ...

  6. PHP中的接口

    对象接口 使用接口(interface),可以指定某个类必须实现哪些方法,但不需要定义这些方法的具体内容. 接口是通过 interface 关键字来定义的,就像定义一个标准的类一样,但其中定义所有的方 ...

  7. 第1章 Java开发入门

    一.填空题 1.Java SE.Java EE.Java ME 2.JRE 3.javac 4.bin 5.path.-class path 二.判断题 1.√ 2.× JDK: java devel ...

  8. 使用chattr禁止文件被删除

    chattr 是个啥? chattr 修改文件在Linux第二扩展文件系统(E2fs)上的特有属性 使用方法 +i or -i 设置/取消文件不能进行修改:即你不能删除它, 也不能给它重新命名,你不能 ...

  9. 如何利用 CSS 的动画原理,创作一个乒乓球对打动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/rvgLzK 可交互视频教 ...

  10. 数据结构(四) 图(Graph)

    在图形结构中,结点之间的关系可以是任意的. 一.图 图由定点(vertex)和边(edge)两个有限集合组成: Graph=(V,R) V是定点集,R={E},E是边集. 有向图(directed n ...