博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforce GYM 100741 A. Queries
阅读量:6234 次
发布时间:2019-06-22

本文共 2968 字,大约阅读时间需要 9 分钟。

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

Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my friend, a mathematician, thinks that it is very fun to play with a sequence of integer numbers. He writes the sequence in a row. If he wants he increases one number of the sequence, sometimes it is more interesting to decrease it (do you know why?..) And he likes to add the numbers in the interval [l;r]. But showing that he is really cool he adds only numbers which are equal some mod (modulo m).

Guess what he asked me, when he knew that I am a programmer? Yep, indeed, he asked me to write a program which could process these queries (n is the length of the sequence):

  • + p r It increases the number with index p by r. ()

    You have to output the number after the increase.

  • - p r It decreases the number with index p by r. () You must not decrease the number if it would become negative.

    You have to output the number after the decrease.

  • s l r mod You have to output the sum of numbers in the interval  which are equal mod (modulo m). () ()
Input

The first line of each test case contains the number of elements of the sequence n and the number m. (1 ≤ n ≤ 10000) (1 ≤ m ≤ 10)

The second line contains n initial numbers of the sequence. (0 ≤ number ≤ 1000000000)

The third line of each test case contains the number of queries q (1 ≤ q ≤ 10000).

The following q lines contains the queries (one query per line).

Output

Output q lines - the answers to the queries.

Examples
input
3 4 1 2 3 3 s 1 3 2 + 2 1 - 1 2
output
2 3 1 看一下数据范围, m<=20 果断开20个树状数组 注意:要开long long
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define lli long long int 8 using namespace std; 9 const lli MAXN=10001;10 void read(lli &n)11 {12 char c='+';lli x=0;bool flag=0;13 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}14 while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();15 n=flag==1?-x:x;16 }17 lli n,m;18 struct node19 {20 lli a[MAXN];21 lli lowbit(lli x){ return x&(-x);}22 lli change(lli pos,lli val)23 {24 for(;pos<=n;pos+=lowbit(pos))25 a[pos]+=val;26 }27 lli query(lli l,lli r)28 {29 return ask(r)-ask(l-1);30 }31 lli ask(lli pos)32 {33 lli ans=0;34 for(;pos;pos-=lowbit(pos))35 ans+=a[pos];36 return ans;37 } 38 node(){memset(a,0,sizeof(a));}39 }bit[21];40 lli date[MAXN];41 int main()42 {43 read(n);read(m);44 for(lli i=1;i<=n;i++)45 {46 read(date[i]);47 bit[date[i]%m].change(i,date[i]);48 }49 lli T;read(T);50 while(T--)51 {52 char how;cin>>how;53 if(how=='+')54 {55 lli p,num;read(p);read(num);56 bit[date[p]%m].change(p,-date[p]);57 date[p]+=num;58 bit[date[p]%m].change(p,date[p]);59 printf("%lld\n",date[p]);60 }61 else if(how=='-')62 {63 lli p,num;read(p);read(num);64 if(date[p]

 

 

转载地址:http://amqna.baihongyu.com/

你可能感兴趣的文章
SQL中 EXCEPT、INTERSECT用法
查看>>
基于Token的WEB后台认证机制
查看>>
[Python] Reuse Code in Multiple Projects with Python Modules
查看>>
026——VUE中事件修饰符之使用$event与$prevent修饰符操作表单
查看>>
dynamic web module讲解
查看>>
C# 过滤特殊字符,保留中文,字母,数字,和-
查看>>
Pycharm安装详细教程
查看>>
WPF自定义LED风格数字显示控件
查看>>
Linux编译步骤概述
查看>>
Ubuntu环境使用apt命令下载管理包的优势
查看>>
如何利用MongoDB打造TOP榜小程序
查看>>
Eureka自我保护模式——难点重点
查看>>
Android中Handler的使用[一]
查看>>
用于不同服务器数据库之间的数据操作
查看>>
产品部和业务部门的利益之争
查看>>
手机网页 右边的空白区
查看>>
Fedora 9中“网卡无法自动激活”的解决方法
查看>>
translate under shell with alias
查看>>
Utf-8和Gb2312乱码问题的终结
查看>>
linux命令详解:jobs命令
查看>>