线段树 A题
来源:互联网 发布:网王之知世年华 编辑:程序博客网 时间:2024/06/05 22:46
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N= 50000;
long a[N];
int n, q;
int b1,b2,b3;
int flag;
int main()
{
cin>>n>>q;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=q; i++)
{
long sum=0;
char temp;
cin>>temp;
if(temp=='Q')
{
cin>>b1>>b2;
for(int j=b1; j<=b2; j++)
sum+=a[j];
flag=1;
}
else if(temp=='C')
{
cin>>b1>>b2>>b3;
for(int j=b1; j<=b2; j++)
a[j]+=b3;
}
if(flag==1)
{
flag=0;
cout<<sum<<endl;
}
}
return 0;
}
#include <cstring>
#include <algorithm>
using namespace std;
const int N= 50000;
long a[N];
int n, q;
int b1,b2,b3;
int flag;
int main()
{
cin>>n>>q;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=q; i++)
{
long sum=0;
char temp;
cin>>temp;
if(temp=='Q')
{
cin>>b1>>b2;
for(int j=b1; j<=b2; j++)
sum+=a[j];
flag=1;
}
else if(temp=='C')
{
cin>>b1>>b2>>b3;
for(int j=b1; j<=b2; j++)
a[j]+=b3;
}
if(flag==1)
{
flag=0;
cout<<sum<<endl;
}
}
return 0;
}
阅读全文
0 0
- 线段树 A题
- A 线段树
- hdu1698_Just a Hook(线段树)
- 线段树----A - 敌兵布阵
- hdu1698just a hook 线段树
- [线段树]CodeForces 356A
- Just a Hook(线段树)
- 线段树 Just a Hook
- HDU5685 Problem A 线段树
- 线段树 Just a hook
- Codeforces Round #179 (Div. 1) A题 线段树
- Just a Hook +线段树区间更新模板题
- hdu1698Just a Hook 线段树 成段更新水题
- hdu 1698 Just A Hook 线段树的一道题
- 2016 UESTC Training for Data Structures A题 线段树
- HDU1698 Just a Hook 线段树入门题复习
- hdu1698 Just a Hook 线段树区间更新,模板题
- A Simple Problem with Integers ----线段树的模板题
- ?selectableItemBackground 水波纹效果
- 【HDU2136】 Largest prime factor
- 设备管理-操作系统-程序员面试
- zoj3623
- 多种脚本语言及熟悉一门
- 线段树 A题
- 写一个彩票程序 30选7 随机(1~30中间)生成7个随机数,注意不能重复然后输入7个数,对比7个数是否与随机数有相同的,如果有显示“中了几个号” 如果中了7个号,显示一等奖 如果中了6个号,显示二
- 第三章 python数据规整化
- Dreamoon and Sets CodeForces
- adsfjkkdshfkasjfk
- 使用ajax提交form表单,包括ajax文件上传
- left join 和 left outer join 的区别
- mysql查询数据库中重复的字段的值
- 8月3日PHP学习笔记