CF GYM 100741 A Queries

A. Queries
time limit per test0.25 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard 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

#include<bits/stdc++.h>
#define MAXN 10010
#define LL long long
using namespace std;
struct BIT {
    LL c[MAXN];
    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=0;
        for(;x;x-=lowbit(x)) ret+=c[x];
        return ret;
    }
    LL query(int l,int r){ return query(r)-query(l-1); }
}bit[20];
int n,m,T;
LL a[MAXN];
int main() {
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; i++) bit[i].n=n;
    for(int i=1; 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[10];
        scanf("%s%d%d",opt,&x,&y);
        if(opt[0]=='+'){
            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[0]=='-'){
            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[0]=='s'){
            scanf("%d",&z);
            printf("%lld\n",bit[z].query(x,y));
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
自2020年以来,自动驾驶汽车(Autonomous Vehicle)在这一领域取得了显著进展。 自动驾驶汽车通过使用先进的传感技术,如雷达、激光雷达和摄像头,以及深度学习和人工智能算法,实现了车辆的自主驾驶。它们能够感知周围环境,了解道路状况,并做出相应的决策和行驶动作,从而实现无需人类操控的车辆行驶。 自动驾驶汽车在2020年迅速崭露头角。它们的技术日益成熟,不断的实验和测试表明其在安全性和性能方面已经取得了显著的突破。虽然仍然存在一些挑战,比如在复杂城市环境中导航和处理紧急情况,但这些问题正经过不断的研究和改进来得以解决。 在未来,自动驾驶汽车有望在各个领域发挥重要作用。首先,它们将可以提高道路交通的安全性。由于自动驾驶车辆不受人类司机的疲劳、分心和驾驶误差的限制,它们的驾驶能力更为稳定和准确。其次,自动驾驶汽车还能够提高交通效率。通过与其他车辆实时通信和协同,它们可以避免交通堵塞和减少事故发生,从而减少交通拥堵和行车时间成本。 此外,自动驾驶汽车也将为交通出行带来便利和舒适性。乘客可以更轻松地进行其他活动,如工作、休息或娱乐,而不必担心驾驶问题。老年人和残障人士也将能够自由独立地出行,提高他们的生活质量。 综上所述,作为2020年的重要趋势,自动驾驶汽车具有广阔的应用前景。通过不断的创新和发展,它们将在道路交通安全、交通效率和出行体验方面取得进一步的提升。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值