传送门

题目大意:

一个长度为n的序列,q次三种操作

+p  r:下标为p的数+r

-p r:下标为p的数-r

s l r mod [L,R]中有多少数%m=mod,m已经给出

题解:

开十个树状数组

代码

我的

#include<iostream>
#include<cstdio>
using namespace std; int n,m,q,l,r,od,p,mod,a[];
struct Tree{
int tre[];
}s[]; int lowbit(int x){
return x&(-x);
} void add(int k,int p){
while(p<=n){
s[k].tre[p]++;
p+=lowbit(p);
}
} void modify(int k,int p,int x){
while(p<=n){
s[k].tre[p]+=x;
p+=lowbit(x);
}
} int sum(int l,int r,int mod){
int cntl=,cntr=;l--;
while(l){
cntl+=s[mod].tre[l];
l-=lowbit(l);
}
while(r){
cntr+=s[mod].tre[r];
r-=lowbit(r);
}
return cntr-cntl;
} int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
add(a[i]%m,i);
}
for(int i=;i<=q;i++){
scanf("%d",&od);
if(od==){
scanf("%d%d",&p,&r);
modify(a[p]%m,p,-);
a[p]+=r;
modify(a[p]%m,p,);
}
if(od==){
scanf("%d%d",&p,&r);
modify(a[p]%m,p,-);
a[p]-=r;
modify(a[p]%m,p,);
}
if(od==){
scanf("%d%d%d",&l,&r,&mod);
printf("%d\n",sum(l,r,mod));
}
}
return ;
}

丁神的

#include<bits/stdc++.h>
#define N 10010
#define ll long long
using namespace std; struct BIT {
ll c[N];
int n; int lowbit(int x) {
return x&(-x);
}
void modify(int x,ll y) {
for(; x<=n; x+=lowbit(x)) c[x]+=y;
}
ll query(int x) {
ll ret=;
for(; x; x-=lowbit(x)) ret+=c[x];
return ret;
} ll query(int l,int r) {
return query(r)-query(l-);
}
} bit[]; int n,m,T;
ll a[N]; int main() {
scanf("%d%d",&n,&m);
for(int i=; i<m; i++) bit[i].n=n;
for(int i=; i<=n; i++) {
scanf("%lld",&a[i]);
bit[a[i]%m].modify(i,a[i]);
}
scanf("%d",&T);
while(T--) {
int x,y,z;
char opt[];
scanf("%s%d%d",opt,&x,&y);
if(opt[]=='+') {
bit[a[x]%m].modify(x,-a[x]);
a[x]+=y;
bit[a[x]%m].modify(x,a[x]);
printf("%lld\n",a[x]);
}
if(opt[]=='-') {
if(a[x]<y) {
printf("%lld\n",a[x]);
} else {
bit[a[x]%m].modify(x,-a[x]);
a[x]-=y;
bit[a[x]%m].modify(x,a[x]);
printf("%lld\n",a[x]);
}
}
if(opt[]=='s') {
scanf("%d",&z);
printf("%lld\n",bit[z].query(x,y));
}
}
return ;
}

GYM 100741A Queries的更多相关文章

  1. Codeforces GYM 100741A . Queries

    time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...

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

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

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

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

  4. 100741A Queries

    传送门 题目 Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my f ...

  5. 暑假集训-WHUST 2015 Summer Contest #0.1

    ID Origin Title   4 / 12 Problem A Gym 100589A Queries on the Tree 14 / 41 Problem B Gym 100589B Cou ...

  6. 【 Gym - 101138D 】Strange Queries (莫队算法)

    BUPT2017 wintertraining(15) #4B Gym - 101138D 题意 a数组大小为n.(1 ≤ n ≤ 50 000) (1 ≤ q ≤ 50 000)(1 ≤ ai ≤  ...

  7. codeforce GYM 100741 A Queries

    A. Queries time limit per test:0.25 s memory limit per test:64 MB input:standard input output:standa ...

  8. Codeforces Gym 101138 D. Strange Queries

    Description 给你一下长度为 \(n\) 的序列. \(a_i=a_j\) \(l_1 \leqslant i \leqslant r_1\) \(l_2 \leqslant i \leqs ...

  9. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

随机推荐

  1. Windows下部署多个Tomcat

    编辑bin/startup.bat SET JAVA_HOME=...(JDK所在路径) SET CATALINA_HOME=...(Tomcat解压的路径) 编辑server.xml文件 <! ...

  2. python远程访问hive

    #!/usr/bin/pythonimport syssys.path.append('/home/zhoujie/Downloads/hive-0.7.0-cdh3u0/lib/py')from h ...

  3. 上篇:es5、es6、es7中的异步写法

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/es-async 本博客同步在http://www.cnbl ...

  4. vue - 前置工作 - 目录功能介绍

    一个DEMOS的完整目录(由于GWF问题,我就不一一打开网站一个个去搜索并且解释了)可以去关注:https://www.cnblogs.com/ye-hcj build build.js(本文来自ht ...

  5. HDOJ 1217 Arbitrage(拟最短路,floyd算法)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. php操作xml的方法

    xml源文件 <?xml version="1.0 encoding="UTF-8"?> <humans> <zhangying> & ...

  7. LINQ解决依据某个字段去重

    想要List结果反复 的数据非常easy.仅仅要.Dinstinct()就好了 可是假设想要依据某个字段去除反复的数据,上面的方法就帮不上忙了.我们须要重写一个方法.直接上样例吧 [Serializa ...

  8. centos 安装php7 memcached扩展

    在使用下面这种方式安装php7 memcached扩展时,先要安装好memcached服务器yum -y install php70w-pecl-memcached

  9. Facebook内部高效工作指南

    文章来源: TopDigital http://news.ittime.com.cn/usershow/main?userid=2826 [IT时代网.IT时代周刊编者按]每一个人工作中都会遇到力不从 ...

  10. Mac OS安装Scrapy

    个人觉得掌握简单的爬虫知识非常有用,特别是想要从一些特定网站自动地下载一些资源或者统计一些数据,非常的有用.对于产品经理来说,如果要了解竞争产品.替代产品的价格,可以写一个爬虫脚本从各大电商网站爬取相 ...