Potentiometers
题意:
线段树的单点修改,区间查询
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<1|1
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 200010
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int num[N<<],n,q;
void pushup(int rt){
num[rt]=num[rt<<]+num[rt<<|];
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d",&num[rt]);
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
}
void update(int p,int b,int l,int r,int rt){
if(l==r){
num[rt]=b;
return;
}
int m=(l+r)>>;
if(p<=m)update(p,b,lson);
else update(p,b,rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
return num[rt];
}
int m=(l+r)>>;
int sum=;
if(L<=m)sum+=query(L,R,lson);
if(R>m)sum+=query(L,R,rson);
pushup(rt);
return sum;
}
int main()
{
char s[];
int a,b,cas=;
while(~scanf("%d",&n)&&n){
cas++;
if(cas!=)printf("\n");
build(,n,);
printf("Case %d:\n",cas);
while(~scanf("%s",s)){
if(s[]=='E')
break;
else if(s[]=='M'){
scanf("%d%d",&a,&b);
printf("%d\n",query(a,b,,n,));
}
else if(s[]=='S'){
scanf("%d%d",&a,&b);
update(a,b,,n,);
}
}
}
return ;
}
Potentiometers的更多相关文章
- UVALive 2191 Potentiometers (树状数组)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- LA 2191 - Potentiometers
看题传送门 Fenwick树的应用~~~ #include <cstdio> #include <cstring> #include<algorithm> usin ...
- VSim [a Racing-simulator by Vell001]
VSim [a racing-simulator by vell001] This is my first project about Racing. I am a Chinese with bad ...
- PID控制器(比例-积分-微分控制器)- V
Linear Actuator - PID Control Introduction This application guide is designed to explain the basics ...
- PID控制器(比例-积分-微分控制器)- IV
调节/测量放大电路电路图:PID控制电路图 如图是PlD控制电路,即比例(P).积分(I).微分(D)控制电路. A1构成的比例电路与环路增益有关,调节RP1,可使反相器的增益在0·5一∞范围内变化; ...
- PID DC/DC Converter Controller Using a PICmicro Microcontroller
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011794 ...
- Digital Adjustment of DC-DC Converter Output Voltage in Portable Applications
http://pdfserv.maximintegrated.com/en/an/AN818.pdf http://www.maximintegrated.com/app-notes/index.mv ...
- CMOS DACs act as digitally controlled voltage dividers
Digital potentiometers, such as Analog Devices’ AD5160, make excellent digitally controlled voltage ...
- ADC for programmable logic uses one capacitor
Many electronic devices require user input for setting the application properties. Typical input dev ...
随机推荐
- Kafka生产者----向kafka写入数据
开发者可以使用kafka内置的客户端API开发kafka应用程序.除了内置的客户端之外,kafka还提供了二进制连接协议,也就是说,我们直接向kafka网络端口发送适当的字节序列,就可以实现从Kafk ...
- MySQL Connector/Python 接口 (三)
本文参见这里. 使用缓冲的 cursor,下例给从2000年加入公司并且还在公司的员工薪水从明天起加15% from __future__ import print_function from dec ...
- java读utf8 的txt文件,第一个字符为空或问号问题
参考:https://blog.csdn.net/yangzhichao888/article/details/79529756 https://blog.csdn.net/wangzhi291/ar ...
- Leetcode 211.添加与搜索单词
添加与搜索单词 设计一个支持以下两种操作的数据结构: void addWord(word) bool search(word) search(word) 可以搜索文字或正则表达式字符串,字符串只包含字 ...
- 【CodeChef】KNGHTMOV(方案数DP)
题意: 考虑一张无限大的方格棋盘.我们有一个“骑士”,它必须从(0,0)格开始,按照如下规则,移动至(X,Y)格:每一步,它只能从(u,v)格移动至(u+Ax,v+Ay)或者(u+Bx,v+By).注 ...
- hdu - 2066 一个人的旅行(基础最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...
- Spring Boot-Logback 配置(区分环境、分包、分级别打印)
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!--生产环境 - ...
- Ubuntu 16.04安装Memcached(单机)
Ubuntu 16.04安装Memcached,不过不仅限与Ubuntu,可以用CentOS等去安装,只不过测试时使用的是Ubuntu机器.Windows下不建议使用,本机调试可以使用,线上环境除了W ...
- searchIndexer.exe占用过高CPU
1.searchIndexer.exe占用过高CPU很可能是Windows的索引损坏造成的. 这时候只要进入控制面板—索引选项—高级—重建即可解决 2. net stop "windows ...
- NetworkManager的坑(如何让network manager不去管理网络端口)
在CentOS上,有时你需要停止并禁用 NetworkManager.但这样做了之后,其实NetworkManager还在影响着你的端口. 比如你有端口配置如下: [root@compute02 ~] ...