GYM 100741A Queries
题目大意:
一个长度为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的更多相关文章
- Codeforces GYM 100741A . Queries
time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...
- GYM 100741A Queries(树状数组)
A. Queries time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input ...
- gym 100589A queries on the Tree 树状数组 + 分块
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数 ...
- 100741A Queries
传送门 题目 Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my f ...
- 暑假集训-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 ...
- 【 Gym - 101138D 】Strange Queries (莫队算法)
BUPT2017 wintertraining(15) #4B Gym - 101138D 题意 a数组大小为n.(1 ≤ n ≤ 50 000) (1 ≤ q ≤ 50 000)(1 ≤ ai ≤ ...
- 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 ...
- Codeforces Gym 101138 D. Strange Queries
Description 给你一下长度为 \(n\) 的序列. \(a_i=a_j\) \(l_1 \leqslant i \leqslant r_1\) \(l_2 \leqslant i \leqs ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
随机推荐
- nginx原配置
#原配置 server { listen ; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main ...
- 提高google网站访问速度
修改:C:\Windows\System32\drivers\etc\hosts文件 # google websites.203.208.46.180 ssl.gstatic.com203.208.4 ...
- 如何细粒度地控制你的MyBatis二级缓存(mybatis-enhanced-cache插件实现)
前几天网友chanfish 给我抛出了一个问题,笼统地讲就是如何能细粒度地控制MyBatis的二级缓存问题,酝酿了几天,觉得可以写个插件来实现这个这一功能.本文就是从问题入手,一步步分析现存的MyBa ...
- (二)《机器学习》(周志华)第4章 决策树 笔记 理论及实现——“西瓜树”——CART决策树
CART决策树 (一)<机器学习>(周志华)第4章 决策树 笔记 理论及实现——“西瓜树” 参照上一篇ID3算法实现的决策树(点击上面链接直达),进一步实现CART决策树. 其实只需要改动 ...
- 关于Lisp和函数式编程 & 各种语言对比 & TIOBE
上一篇文章提到了,今天又读到Lisp的一些内容 <为什么Lisp如此先进>ruanyifeng(Link).关于Lisp的八卦,可以参考我前面两篇文章 http://www.cnblogs ...
- SolidEdge 如何由装配图快速生成爆炸视图
建立图纸精灵,组态中选择explode(没有下一步可选了) 点击完成即可绘制爆炸图
- v-if v-else-if v-else
1.代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- JSP简明教程:汇总
原创JSP教程,简洁明了,不含废话. JSP简明教程(一):JSP简单介绍 JSP简明教程(二):JSP基本的语法 JSP简明教程(三):JSP隐含对象 JSP简明教程(四):EL表达式语言.Java ...
- 1 npoi 网上 不用模板 设置密码 workbook.WriteProtectWorkbook("password", "admin"); 、、 2 locked.IsLocked = true; sheet1.ProtectSheet("password");NPOI操作EXCEL--设置密码才可以修改单元格内容 3 模板设置密码 确定原密码 设置新密码
1 workbook.WriteProtectWorkbook("password", "admin"); 还是可以进去 只读进去 可以编辑 编辑就另存为 ...
- 【转载】C#相等性比较
本文阐述C#中相等性比较,其中主要集中在下面两个方面 ==和!=运算符,什么时候它们可以用于相等性比较,什么时候它们不适用,如果不使用,那么它们的替代方式是什么? 什么时候,需要自定一个类型的相等性比 ...