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 ...
随机推荐
- Base64的空格 + 问题...
BASE64 通过url传递到后台 加号变空格的处理方法 解决方法: 前台处理:str.replace("+", "%2B"); (错误) <scrip ...
- jQuery -> 获取后代元素的三种方法
假设我们有内容例如以下的html文件,那么怎样选取包括在<p>元素内的<i>元素呢? 邪馬台国の謎と弥生時代 紀元前1000年ごろ.水稲工作の技術をもつ集団が大挙して日本に移住 ...
- 生活娱乐 WIFI机器人(某机器发烧友自己动手做一台)
某机器发烧友自己动手做一台WIFI机器人,以下是这位发烧友的自述!让我们一起来分享他的劳动成果-- 在经历了十多天的疯狂淘宝.组装.调试.拆卸.再组装.再调试的过程后,俺的Wifi Robot终于于2 ...
- Android中View的事件分发机制——Android开发艺术探索笔记
原文链接 http://sparkyuan.me/ 转载请注明出处 介绍 点击事件的事件分发就是对MotionEvent事件的分发过程.当一个MotionEvent产生了以后,系统须要把这个事件传递给 ...
- ActiveMQ(一) 转
package pfs.y2017.m11.mq.activemq.demo01; import javax.jms.Connection; import javax.jms.DeliveryMode ...
- npm的安装和更新
https://nodejs.org官网下载软件安装 验证是否安装,进入命令行 输入npm -v 这个是安装node自动带的工具 npm install npm@xxx 自动更新自己,后边跟版本号 n ...
- W5500EVB TCP Server演示
之前给大家展示了p=6471" style="margin:0px; padding:0px; border:0px; font-family:inherit; font-size ...
- Visual Studio自动生成文件版本信息
一. 前言 通常,要控制输出文件的版本信息,只需要手动修改资源rc文件中的Version,即可在输出文件的文件属性里查看到对应的版本信息.如下图: 但是,版本号是会随时都更新的,每次bu ...
- Spark SQL is a Spark module for structured data processing.
http://spark.apache.org/docs/latest/sql-programming-guide.html
- CSS3 的10种Loading
昨晚用CSS3实现了几种常见的Loading效果,虽然很简单,但还是分享一下,顺便也当是做做笔记…… 第1种效果: 代码如下: <div class="loading"> ...