题意:往集合里面添加删除数,集合中的数是按从小到大排列的,询问下标模5等于3的数的和。

记得当时这题不会做,

现在想简单多了,只要维护五个值和左右子树的size大小就行了。

#define maxn 100005

struct node
{
int l,r;
int sz;
i64 f[];
int mid()
{
return (l + r ) / ;
}
};
node tt[maxn * ];
struct node1
{
int id ;
i64 x;
};
node1 ml[maxn];
void push_up(int root )
{
int sz ;
sz = tt[root * ].sz;
tt[root].sz = tt[root * ].sz + tt[root * + ].sz;
for(int i = ; i < ; i ++ )
tt[root].f[i] = tt[root * ].f[i] + tt[root * + ].f[(i + - sz % ) % ];
return ;
}
void build(int root ,int l,int r )
{
tt[root].l = l ;
tt[root].r = r ;
tt[root].sz = ;
for(int i = ; i < ; i ++ ) tt[root].f[i] = ;
if(l == r ) return ;
int mid = tt[root].mid();
build(root * , l , mid );
build(root * + , mid + , r);
return ;
}
void update(int root ,int pos ,i64 vv)
{
if(tt[root].l == tt[root].r )
{
if(vv == )
{
tt[root].sz = ;
for(int i = ; i < ; i ++ ) tt[root].f[i] = ;
}
else
{
tt[root].sz = ;
for(int i = ; i < ;i ++ ) tt[root].f[i] = ;
tt[root].f[] = vv;
}
return ;
}
int mid = tt[root].mid();
if(pos <= mid )
update(root * , pos , vv);
if(pos > mid )
update(root * + , pos , vv);
push_up(root);
}
int num;
i64 b[maxn];
int pos[maxn];
char str[];
int main()
{
int x;
int n ;
while(scanf("%d",&n)!=EOF)
{
num = ;
for(int i = ;i <= n ; i ++ )
{
scanf("%s",str);
if(str[] == 'a')
{
ml[i].id = ;
scanf("%I64d",&ml[i].x);
b[num++] = ml[i].x;
}
else if(str[] == 'd')
{
ml[i].id = ;
scanf("%I64d",&ml[i].x);
b[num++] = ml[i].x;
}
else
{
ml[i].id = ;
}
}
sort(b ,b + num);
int pos;
num = unique(b,b+num) - b;
build(,,num);
for(int i = ; i <= n ; i ++ )
if(ml[i].id != )
{
pos = lower_bound(b , b + num , ml[i].x) - b + ;
if(ml[i].id == )
update(,pos,ml[i].x);
else update(,pos,);
}
else
{
printf("%I64d\n",tt[].f[]);
}
}
return ;
}

hdu4288 Coder 2012成都网络赛 A题的更多相关文章

  1. HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)

    We Love MOE Girls Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. HDU 4737 A Bit Fun (2013成都网络赛)

    A Bit Fun Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  7. ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval

    ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...

  8. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  9. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. Outlook将收到邮件的附件保存在磁盘

    1. 新建一个宏 1)文件->选项->自定义功能区, 把主选项卡的 开发工具勾选上. 2)开发工具->宏,输入宏名,创建. 加入以下代码 Public Sub SaveAttach( ...

  2. 设计模式(一)工厂模式Factory(创建类型)

    设计模式一 工厂模式Factory 在面向对象编程中, 最通常的方法是一个new操作符产生一个对象实例,new操作符就是用来构造对象实例的.可是在一些情况下, new操作符直接生成对象会带来一些问题. ...

  3. Case when 的使用方法

    SQL Case when 的使用方法 Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THE ...

  4. Arduino 数码管LED驱动 数组法

    上个样例讲到驱动LED数码管,採用一种最直接的方案,对每一个LED进行高低电平的控制,这种长处是每一个LED都是受控可检的,避免了因为短路造成的假象,但对于数字变化来说,写起来就很冗余,因此这次尝试用 ...

  5. 几种流行Webservice控制框架

     转会[http://blog.csdn.net/thunder4393/article/details/5787121],写的非常好,以收藏. 1      摘要 开发webservice应用程序中 ...

  6. Web Service简单入门示例

    Web Service简单入门示例     我们一般实现Web Service的方法有非常多种.当中我主要使用了CXF Apache插件和Axis 2两种. Web Service是应用服务商为了解决 ...

  7. ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]

    门户:problemCode=3635">ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 ...

  8. (转)mvn clean install 与 mvn install 的区别(为啥用clean)

    之前写代码的过程中曾经遇到过问题,用mvn install后,新改的内容不生效,一定要后来使用mvn clean install 才生效,由于之前没有做记录,以及记不清是什么情况下才会出现的问题,于是 ...

  9. IntelliJ 15 unmapped spring configuration files found

    IntelliJ Spring Configuration Check 用IntelliJ 导入现有工程时,如果原来的工程中有spring,每次打开工程就会提示:Spring Configuratio ...

  10. main thread starting…

    例的结果,下面的: main thread starting- Thrad 2 staring- Thrad 2 end- Thrad 4 staring- Thrad 4 end- Thrad 1 ...