题目传送门

 #include <cstdio>
#include <cstring>
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1 const int MAX_N = + ;
int sum[MAX_N << ]; void pushup(int rt)
{
if (rt >> % == )
sum[rt] += sum[rt >> ];
if (rt >> | % == )
sum[rt] += sum[rt >> | ];
} void build(int l, int r, int rt)
{
sum[rt] = r - l + ;
if (l == r)
{
return ;
}
int m = (l + r) >> ;
build (lson);
build (rson);
pushup (rt);
} void update(int p, int l, int r, int rt)
{
if (l == r)
{
sum[rt] = p;
return ;
}
int m = (l + r) >> ;
if (p <= m) update (p, lson);
else update (p, rson); pushup (rt);
} int main(void) //HDOJ 4288 Coder
{
//freopen ("inG.txt", "r", stdin);
int n;
char op[];
int x; while (~scanf ("%d", &n))
{
build (, n, );
while (n--)
{
scanf ("%s", &op);
if (strcmp (op, "add") == )
{
scanf ("%d", &x);
update (x, , n, );
}
if (strcmp (op, "del") == )
{
scanf ("%d", &x);
update (-x, , n, );
}
if (strcmp (op, "sum") == )
{
printf ("%d\n", sum[]);
}
}
} return ;
}

线段树(单点更新) HDOJ 4288 Coder的更多相关文章

  1. 线段树(单点更新) HDOJ 2795 Billboard

    题目传送门 /* 主要利用线段树求区间最值,sum[]代表位置可用空间 每次找到最大值的位置 功能:查询最靠前能容纳广告的位置 */ #include <cstdio> #include ...

  2. 线段树(多棵) HDOJ 4288 Coder

    题目传送门 题意:集合,add x, del x, 求和 分析:首先,暴力可以过这题.用上线段树能大大降低时间的消耗,具体就是类似开了5棵线段树,每个节点都有5个空间,表示该区间的id%5后的和,区间 ...

  3. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  4. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  5. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  6. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  8. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

  9. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

随机推荐

  1. VB.NE总结

    VB.NET视频看完了.但台湾微软资深讲师的声音还回荡在我的脑海中啊.刚開始听两位老师的讲课那是一个纠 结.感觉不亚于听英语听力训练.后来看到王鹏同学转载的台湾计算机术语和大陆计算机术语的对比,我才明 ...

  2. STL review:vector & string & map & struct

    I.vector 1.头文件:#include<vector>                        //容器vector是一个能实现随机存取.插入删除的动态数组,还可以当栈使. ...

  3. HDU 6125 Free from square 状态压缩DP + 分组背包

    Free from square Problem Description There is a set including all positive integers that are not mor ...

  4. CentOS笔记-常用网络命令

    1.curl & wget 使用curl或wget命令,不用离开终端就可以下载文件.如你用curl,键入curl -O后面跟一个文件路径.wget则不需要任何选项.下载的文件在当前目录. cu ...

  5. nlp_tool

    http://www.afenxi.com/post/9700 11款开放中文分词引擎大比拼 附录评测数据地址http://bosonnlp.com/dev/resource 各家分词系统链接地址Bo ...

  6. .Net之路(十四)com组件、OLEDB导入EXCEL

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/chenfanglincfl/article/details/30546777 .NET com组件 ...

  7. SWT.Shell

    import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class SWT_Shell ...

  8. linux 一个超简单的makefile

    makefile 自动化变量:   $@ : 规则的目标文件名  例如:main:main.o test.o                    g++ -Wall -g  main.o test. ...

  9. String bulit-in function

    tip: 和tuple一样,字符串也是不可变的类型,字符串的内建函数有非常多,我们一一举例来看看他们的作用 下面是用dir(str) 输出的内容: ['__add__', '__class__', ' ...

  10. silverlight 图片引入代码

    private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e) { string str = t ...