ZOJ 3279
线段树单点更新
//============================================================================
// Name : E.cpp
// Author : L_Ecry
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100050
using namespace std;
int sum[N*];
int a[N];
void build(int l,int r,int i)
{
if(l==r)
{
sum[i]=a[l];
return ;
}
int mid=(l+r)>>;
build(l,mid,i<<);
build(mid+,r,i<<|);
sum[i]=sum[i<<]+sum[i<<|];
}
void update(int l,int r,int p,int va,int i)
{
if(l==r)
{
sum[i]=va;
return ;
}
int mid=(l+r)>>;
if(p<=mid)update(l,mid,p,va,i<<);
else update(mid+,r,p,va,i<<|);
sum[i]=sum[i<<]+sum[i<<|];
}
int query(int l,int r,int va,int i)
{
if(l==r)
{
return l;
}
int mid=(l+r)>>;
if(va<=sum[i<<])return query(l,mid,va,i<<);
else return query(mid+,r,va-sum[i<<],i<<|);
}
int n,m;
void init()
{
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
build(,n,);
}
void solve()
{
scanf("%d",&m);
while(m--)
{
char c;
int x,y;
scanf(" %c",&c);
if(c=='q')
{
scanf("%d",&x);
printf("%d\n",query(,n,x,));
}
else
{
scanf("%d%d",&x,&y);
update(,n,x,y,);
}
}
}
int main() {
while(scanf("%d",&n)!=EOF)
{
init();
solve();
}
return ;
}
ZOJ 3279的更多相关文章
- ZOJ 3279-Ants(线段树)
传送门:zoj 3279 Ants Ants Time Limit: 2 Seconds Memory Limit: 32768 KB echo is a curious and cleve ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 【枚举】POJ 3279
直达–>POJ 3279 Fliptile 题意:poj的奶牛又开始作孽了,这回他一跺脚就会让上下左右的砖块翻转(1->0 || 0->1),问你最少踩哪些砖块才能让初始的砖块全部变 ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
随机推荐
- java的重修之路
一.内存管理 java里的声明分引用与基本数据类型. 数组: java里new一个对象数组为 person[] A; A = new person[4]; person[0] = new pers ...
- org.apache.jasper.JasperException: Expecting "jsp:param" standard action with "name" and "value" attributes
jasper 英 ['dʒæspə] 美 ['dʒæspɚ] 跟读 口语练习 n. 碧玉:墨绿色 n. (Jasper)人名:(德)雅斯佩尔:(西)哈斯佩尔 JasperException 异 ...
- Hibernate的集合映射与sort、order-by属性
[Hibernate]Hibernate的集合映射与sort.order-by属性 常用集合Set.List.Map,相信大家都很熟悉,面试中也会经常问.Set和List都继承了Collection接 ...
- linux的ulimit命令
ulimit命令用来限制系统用户对shell资源的访问. 语法: ulimit [-acdfHlmnpsStv] [size] 选项介绍: -a 显示当前所有的资源限制; -c size: ...
- wireshark使用教程
Wireshark: https://www.wireshark.org/ 安装: apt-get install wireshark 教程: http://blog.csdn.net/leichel ...
- 【Todo】Zookeeper学习
首先,Zookeeper是基于Paxos来进行分布式选举管理的,Paxos的内容可以参考我另一篇文章:http://www.cnblogs.com/charlesblc/p/6037004.html ...
- nginx的location root 指令
原文:http://blog.csdn.net/bjash/article/details/8596538 location /img/ { alias /var/www/image/; } #若按照 ...
- BigDecimal类型比较大小
这个类是java里精确计算的类 1 比较对象是否相等 一般的对象用equals,但是BigDecimal比较特殊,举个例子: BigDecimal a=BigDecimal.value ...
- C# Socket编程(2)识别网络主机
通过前面的笔记我们可以知道:一个客户端要想发起一次通信,先决条件就是需要知道运行在服务端程序的主机的IP地址是多少,端口号是多少.然后我们才能够通过这个地址向服务器特定的应用程序发送信息.对于网络上的 ...
- VB的gdi+相关声明
模块: Option Explicit Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, i ...