CodeForces 669 E Little Artem and Time Machine CDQ分治
题意:现在有3种操作,
1 t x 在t秒往multiset里面插入一个x
2 t x 在t秒从multiset里面删除一个x
3 t x 在t秒查询multiset里面有多少x
事情是按照输入顺序发生的,这个人有一个时光机,可以穿梭到那一秒去执行操作。
题解:CDQ分治。3维偏序,第一维是输入顺序,第二维t,然后直接map处理数据就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
struct Node{
int op, t, m, id;
bool operator < (const Node & x){
return t < x.t;
}
}A[N], tmp[N];
int ans[N];
map<int,int> mp;
void cdq(int l, int r){
if(l >= r) return ;
int mid = l + r >> ;
cdq(l, mid);
cdq(mid+, r);
int top = , tl = l, tr = mid + ;
while(tl <= mid && tr <= r){
if(A[tl].t <= A[tr].t){
tmp[++top] = A[tl++];
}
else tmp[++top] = A[tr++];
}
while(tl <= mid){
tmp[++top] = A[tl++];
}
while(tr <= r){
tmp[++top] = A[tr++];
}
for(int i = ; i <= top; i++){
int id = tmp[i].id, op = tmp[i].op;
int m = tmp[i].m;
if(id <= mid && op != ){
if(op == ) mp[m]++;
else mp[m]--;
}
else if(id > mid && op == ){
ans[id] += mp[m];
}
A[l+i-] = tmp[i];
}
for(int i = ; i <= top; i++){
int id = tmp[i].id, op = tmp[i].op;
int m = tmp[i].m;
if(id <= mid && op != ){
if(op == ) mp[m]--;
else mp[m]++;
}
}
}
int main(){
int n;
scanf("%d", &n);
memset(ans, -, sizeof(ans));
for(int i = ; i <= n; i++){
scanf("%d%d%d", &A[i].op, &A[i].t, &A[i].m);
A[i].id = i;
if(A[i].op == ) ans[i] = ;
}
cdq(,n);
for(int i = ; i <= n; i++){
if(ans[i] == -) continue;
printf("%d\n", ans[i]);
}
return ;
}
CodeForces 669 E Little Artem and Time Machine CDQ分治的更多相关文章
- codeforces 669E E. Little Artem and Time Machine(节点为map型的线段树)
题目链接: E. Little Artem and Time Machine time limit per test 2 seconds memory limit per test 256 megab ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
- hdu 3842 Machine Works(cdq分治维护凸壳)
题目链接:hdu 3842 Machine Works 详细题解: HDU 3842 Machine Works cdq分治 斜率优化 细节比较多,好好体会一下. 在维护斜率的时候要考虑x1与x2是否 ...
- Codeforces 1093E Intersection of Permutations [CDQ分治]
洛谷 Codeforces 思路 一开始想到莫队+bitset,发现要T. 再想到分块+bitset,脑子一抽竟然直接开始写了,当然也T了. 最后发现这就是个裸的CDQ分治-- 发现\(a\)不变,可 ...
- Codeforces 1045G AI robots [CDQ分治]
洛谷 Codeforces 简单的CDQ分治题. 由于对话要求互相看见,无法简单地用树套树切掉,考虑CDQ分治. 按视野从大到小排序,这样只要右边能看见左边就可以保证互相看见. 发现\(K\)固定,那 ...
- Codeforces 848C Goodbye Souvenir [CDQ分治,二维数点]
洛谷 Codeforces 这题我写了四种做法-- 思路 不管做法怎样,思路都是一样的. 好吧,其实不一样,有细微的差别. 第一种 考虑位置\(x\)对区间\([l,r]\)有\(\pm x\)的贡献 ...
- Codeforces 526F Pudding Monsters - CDQ分治 - 桶排序
In this problem you will meet the simplified model of game Pudding Monsters. An important process in ...
- Codeforces 848C (cdq分治)
Codeforces 848C Goodbye Souvenir Problem : 给一个长度为n的序列,有q个询问.一种询问是修改某个位置的数,另一种询问是询问一段区间,对于每一种值出现的最右端点 ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
随机推荐
- QScintilla下载与编译
你好,我是大贺! Pou光明 大家好,我又回来了~~ 之前和大家分享的是在c/c++中通过python c api嵌入python解释器,主体都是和python相关的.其实最终要和大家分享的是如何做 ...
- Rust写时复制Cow<T>
写时复制(Copy on Write)技术是一种程序中的优化策略,多应用于读多写少的场景.主要思想是创建对象的时候不立即进行复制,而是先引用(借用)原有对象进行大量的读操作,只有进行到少量的写操作的时 ...
- export,export default,module.exports,import,require之间的区别和关联
module.exports Node 应用由模块组成,采用 CommonJS 模块规范.根据这个规范,每个文件就是一个模块,有自己的作用域.在这些文件里面定义的变量.函数.类,都是私有的,对外不可见 ...
- SpringBoot开发案例之打造十万博文Web篇
前言 通过 Python 爬取十万博文之后,最重要的是要让互联网用户访问到,那么如何做呢? 选型 从后台框架.前端模板.数据库连接池.缓存.代理服务.限流等组件多个维度选型. 后台框架 SpringB ...
- SpringBoot 2 HTTP转HTTPS
@Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat ...
- 使用Typora编写博客并发布
前言 用CSDN写了一段时间,广告漫天飞舞.... 于是在博客园申请了一个账号,然后看见markdown编辑页面的第一眼: 再见^_^ 搜索一波,凭着博客园强大的生态,30多万的用户,第三方的支持应接 ...
- 腾讯物联TencentOS tiny上云初探
2017年中旬曾写过一篇关于物联网平台的文章<微软最完善,百度最“小气” 看微软阿里百度三大物联网云平台对比>.现在已经过去两年了,物联网的格局又发生了不少的变化.不过针对腾讯来说,其物联 ...
- fatal: remote origin already exists.解决方法
git remote add origin1 http://github.com/xxx/xxx.git origin名字冲突,换一个名字 遇到这种问题时表示已经有一个origin,冲突了,可能原因是 ...
- Git使用(码云)
1.安装git软件(码云/GitHub) 2.码云注册,保存代码 3.创建代码托管仓库,仓库名相当于码云上的文件夹 4.写作业并提交 在作业文件夹上,右键选择‘get bash here’ 在黑框里输 ...
- sql server数据库查询链接服务器
服务器对象->链接服务器: 或者 select * from sys.servers: 找到服务器对象名称 select * from [服务器对象名称].[数据库名称].dbo.[表名]: