传送门

题目大意:

一个长度为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. eslint 在webstorm配置

    1.安装nodejs和eslint 2.在 webstorm 的 file - setting搜索eslint,配置eslint路径 3.在项目目录下新建.eslintrc文件 4.配置eslint ...

  2. noip2013货车运输

    P1967 货车运输 题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过 ...

  3. sqlplus登陆scott用户,以及退出连接

    进入sqlplus界面 即登陆成功,PLsql也一样 退出连接:

  4. Spark学习(四)Spark2.3 HA集群的分布式安装

    一.下载Spark安装包 1.从官网下载 http://spark.apache.org/downloads.html 2.从微软的镜像站下载 http://mirrors.hust.edu.cn/a ...

  5. 使用ftrace学习linux内核函数调用

    http://www.cnblogs.com/pengdonglin137/articles/4752082.html 转载: http://blog.csdn.net/ronliu/article/ ...

  6. Java 读写文件大全

    原文:http://www.open-open.com/code/view/1423281836529 java中多种方式读文件 一.多种方式读文件内容. 1.按字节读取文件内容 2.按字符读取文件内 ...

  7. ubuntu 14.04安装nodejs

    http://stackoverflow.com/questions/32902699/cannot-install-ember-on-ubuntu-1404/33495134

  8. 用Meta 取消流量器缓存方便调试

    <!-- 禁止浏览器从本地缓存中调阅页面.--> <meta http-equiv="pragram" content="no-cache"& ...

  9. 通过/proc/cpuinfo判断CPU数量、Multicores、Multithreading、Hyper-threading

    http://blog.sina.com.cn/s/blog_4a6151550100iowl.html 判断依据:1.具有相同core id的cpu是同一个core的超线程.2.具有相同physic ...

  10. zoj1232Adventure of Super Mario(图上dp)

    题目连接: 啊哈哈.点我点我 思路: 这个题目是一个图上dp问题.先floyd预处理出图上全部点的最短路,可是在floyd的时候,把可以用神器的地方预处理出来,也就是转折点地方不能为城堡..预处理完成 ...