Sum of Medians CodeForces - 85D(线段树+离散化)
Sum of Medians
题目链接:CodeForces - 85D
#include <bits/stdc++.h>
using namespace std;
const int maxn=100100;
int a[maxn];
struct node{int x, op;
}input[maxn];
int n, cnt;
void init(){scanf("%d", &n);cnt=1;char s[5];for(int i=0; i<n; i++){scanf("%s", s);if(s[0]=='s') input[i].op=3;else{scanf("%d", &input[i].x);if(s[0]=='a') input[i].op=1;else input[i].op=2;}a[cnt++]=input[i].x;}
}
struct Tree{int l, r, v;long long sum[5];
}tr[maxn<<2];
void updown(int m){tr[m].v=tr[m<<1].v+tr[m<<1|1].v;for(int i=0; i<5; i++) tr[m].sum[i]=0;for(int i=0; i<5; i++){tr[m].sum[i]+=tr[m<<1].sum[i];tr[m].sum[(i+tr[m<<1].v)%5]+=tr[m<<1|1].sum[i];}
}
void build(int m, int l, int r){tr[m].l=l;tr[m].r=r;if(l==r){tr[m].v=0;for(int i=0; i<5; i++) tr[m].sum[i]=0;return;}int mid=(l+r)>>1;build(m<<1, l, mid);build(m<<1|1, mid+1, r);updown(m);
}
void updata(int m, int pos){if(tr[m].l==tr[m].r){tr[m].v=(tr[m].v+1)%2;if(tr[m].v)tr[m].sum[1]=a[tr[m].l];else tr[m].sum[1]=0;return;}int mid=(tr[m].l+tr[m].r)>>1;if(pos<=mid) updata(m<<1, pos);else updata(m<<1|1, pos);updown(m);
}
void solve(){sort(a+1, a+1+cnt);cnt=unique(a+1, a+1+cnt)-(a+1);build(1, 1, cnt);for(int i=0; i<n; i++){int p_x=upper_bound(a+1, a+1+cnt, input[i].x)-(a+1);if(input[i].op==3){printf("%lld\n", tr[1].sum[3]);}else{updata(1, p_x);}}
}
int main(){init();solve();return 0;
}
Sum of Medians CodeForces - 85D(线段树+离散化)相关推荐
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- HDOJ 2492 Ping pong 线段树+离散化
//2492 Ping pong 线段树+离散化 /* 题意: 有一陀人从左到右排成一排,每个人有一个唯一的技能值,每个人都找其他人比赛, 比赛前要再找一个人做裁判,裁判的技能值不能比这两个人都高,也 ...
- poj2528贴海报(线段树离散化)
//poj2528贴海报(线段树离散化) #include<cstring> #include<iostream> #include<cstdio> #includ ...
- poj 2528 Mayor's posters(线段树+离散化)
1 /* 2 poj 2528 Mayor's posters 3 线段树 + 离散化 4 5 离散化的理解: 6 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用 ...
- BZOJ 3836 Codeforces 280D k-Maximum Subsequence Sum (模拟费用流、线段树)
题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=3836 (Codeforces) http://codeforces.com ...
- CodeForces - 1311F Moving Points(线段树+离散化)
题目链接:点击查看 题目大意:给出 x 轴上的 n 个点,每个点都有一个位置和一个速度,每个点会根据速度在 x 轴上移动,现在规定dis( x , y )为点 x 和点 y 在移动过程中的最小距离,我 ...
- Educational Codeforces Round 95 (Rated for Div. 2)D. Trash Problem(权值线段树+离散化)
题目描述 Vova decided to clean his room. The room can be represented as the coordinate axis OX. There ar ...
- poj 2528 Mayor's posters (线段树+离散化)
/*离散化+线段树由于 数据的输入最大是 10000000 ,直接用开数组肯点会超,所以要将起离散话,首先 ,我们存储输入的边,将其离散化,后面的就和一般的线段树一样可. */#include< ...
- POJ - 2299 Ultra-QuickSort(线段树+离散化/归并排序)
题目链接:点击查看 题目大意:给出n个数字,求使用冒泡排序所需要交换的次数 题目分析:这个题n给到了5e5,如果直接冒泡排序的话,的时间复杂度肯定就TLE了,所以不能直接暴力模拟 我们换个思路,这个题 ...
最新文章
- 开发日记 20210316
- 查看windows系统当前使用的字符集
- SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传
- pip安装deb_趟坑:使用pip安装TensorFlow
- DBGridEh导出Excel等格式文件
- ssms中怎么设置自增_如何在SSMS状态栏中设置自定义颜色
- Windows 的开发好痛苦
- STM32库函数 断言机制 宏定义assert_param(expr)和assert_failed的使用方法
- 国内C语言教材中几种值得商榷的说法
- LPDDR4 器件自适应方案实现
- 计算机进入桌面黑屏怎么办,电脑进入桌面后黑屏如何修复 电脑经常进入桌面之后黑屏的处理方法...
- 都说ApiPost香,它到底香在哪里?
- 服务器能打开其他网站打不开,为什么有的网页打不开其他能打开(浏览器网页打不开的原因有哪些)...
- 计算天数(函数)(C语言实现)
- 管理信息系统复试——三、管理信息系统战略规划与开发方法
- android保存播放进度,Android MediaPlayer控制进度播放音频
- vue3 项目中 watch 各种不触发
- 速腾聚创完成新一轮融资:华兴新经济基金领投 筹备上市
- 【论文精度】AutoBERT-Zero (使用NAS搜索预训练语言模型)
- 4.Vue指令(Directives)
热门文章
- linux内核是如何实现分页机制的
- XMind 2021mac苹果手机电脑端 专业版思维导图
- 大话2点卡稳定服务器,大话西游2新区点卡比例增涨太快,这究竟是什么原因
- ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
- Lisseur Professionnel Ghd thé sont diurétiques et se traduira par nous
- Bit Twiddling Hacks
- CCS如何调整字体大小
- Git详解之四:服务器上的Git
- Centos 8 搭建samba文件共享服务(超详细)
- 手机APP远程控制树莓派