传送门

题目大意:

一个长度为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. spring data jpa 查询部分字段

    @Query("select new map(ah as ah,salq as sqlq,yg as yg, bg as bg,ay as ay) FROM Aj where ahdm=?1 ...

  2. linux fork()

    一. linux下C语言可以用fork()建立子进程.fork函数返回两个值,对于子进程,返回0; 父进程,返回子进程ID. 所以用if(fork()==0)      {子进程执行的代码段:}els ...

  3. Codeforces 959 D Mahmoud and Ehab and another array construction task

    Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...

  4. leetcode最长递增子序列问题

    题目描写叙述: 给定一个数组,删除最少的元素,保证剩下的元素是递增有序的. 分析: 题目的意思是删除最少的元素.保证剩下的元素是递增有序的,事实上换一种方式想,就是寻找最长的递增有序序列.解法有非常多 ...

  5. Centos7配置Grafana对接OpenLDAP

    在grafana的主配置文件grafana.ini中开启LDAP认证 注意:grafana有两个地方需要指定(/etc/grafana/grafana.ini和/usr/share/grafana/c ...

  6. 创建es索引-格式化和非格式化

    创建es索引-格式化和非格式化 学习了:https://www.imooc.com/video/15768 索引有结构化和非结构化的区分: 1, 先创建索引,然后POST修改mapping 首先创建索 ...

  7. [UnityUI]一些有趣的UI样例

    1.环形进度条 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  8. Django-权限信息中间件操作

    # 在当前app下新建一个middleware的文件夹,然后就可以尽情的写中间件了,只能是这个名字,切记~@!import re from django.shortcuts import redire ...

  9. HDOJ1006

    #include <cstdio>#include <algorithm>using namespace std;const double UB=43200;const dou ...

  10. leetcode笔记:Pascal&#39;s Triangle

    一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...