Little Artem and Time Machine CodeForces - 669E

2024-02-22 18:32

本文主要是介绍Little Artem and Time Machine CodeForces - 669E,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

http://codeforces.com/problemset/problem/669/E

动态主席树模板题

CDQ分治也可以做 转换为三位偏序 初始给定顺序为第一维 t值为第二维 x值为第三维 代码略

#include <bits/stdc++.h>
using namespace std;struct node1
{int tp;int t;int x;
};struct node2
{int l;int r;int val;
};node1 order[100010];
node2 tree[10000010];
int pret[100010],prex[100010],root[100010];
int q,lent,lenx,num;int lowbit(int x)
{return x&(-x);
}int build(int l,int r)
{int cur,m;cur=num++;if(l==r) return cur;m=(l+r)/2;tree[cur].l=build(l,m);tree[cur].r=build(m+1,r);return cur;
}int updateII(int rot,int tar,int val,int l,int r)
{int cur,m;cur=num++;tree[cur]=tree[rot];tree[cur].val+=val;if(l==r) return cur;m=(l+r)/2;if(tar<=m) tree[cur].l=updateII(tree[rot].l,tar,val,l,m);else tree[cur].r=updateII(tree[rot].r,tar,val,m+1,r);return cur;
}void updateI(int tart,int tarx,int val)
{int i;for(i=tart;i<=lent;i+=lowbit(i)) root[i]=updateII(root[i],tarx,val,1,lenx);
}int queryII(int rot,int tar,int l,int r)
{int m;if(l==r) return tree[rot].val;m=(l+r)/2;if(tar<=m) return queryII(tree[rot].l,tar,l,m);else return queryII(tree[rot].r,tar,m+1,r);
}int queryI(int tart,int tarx)
{int res,i;res=0;for(i=tart;i>=1;i-=lowbit(i)) res+=queryII(root[i],tarx,1,lenx);return res;
}int main()
{int i,pt,px;scanf("%d",&q);for(i=1;i<=q;i++){scanf("%d%d%d",&order[i].tp,&order[i].t,&order[i].x);pret[++lent]=order[i].t;prex[++lenx]=order[i].x;}sort(pret+1,pret+lent+1);sort(prex+1,prex+lenx+1);lent=unique(pret+1,pret+lent+1)-pret-1;lenx=unique(prex+1,prex+lenx+1)-prex-1;root[0]=build(1,lenx);for(i=1;i<=lent;i++) root[i]=root[0];for(i=1;i<=q;i++){pt=lower_bound(pret+1,pret+lent+1,order[i].t)-pret;px=lower_bound(prex+1,prex+lenx+1,order[i].x)-prex;if(order[i].tp==1) updateI(pt,px,1);else if(order[i].tp==2) updateI(pt,px,-1);else printf("%d\n",queryI(pt,px));}return 0;
}

 

这篇关于Little Artem and Time Machine CodeForces - 669E的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/736131

相关文章

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

python中time模块的常用方法及应用详解

《python中time模块的常用方法及应用详解》在Python开发中,时间处理是绕不开的刚需场景,从性能计时到定时任务,从日志记录到数据同步,时间模块始终是开发者最得力的工具之一,本文将通过真实案例... 目录一、时间基石:time.time()典型场景:程序性能分析进阶技巧:结合上下文管理器实现自动计时

MySQL中时区参数time_zone解读

《MySQL中时区参数time_zone解读》MySQL时区参数time_zone用于控制系统函数和字段的DEFAULTCURRENT_TIMESTAMP属性,修改时区可能会影响timestamp类型... 目录前言1.时区参数影响2.如何设置3.字段类型选择总结前言mysql 时区参数 time_zon

Python 标准库time时间的访问和转换问题小结

《Python标准库time时间的访问和转换问题小结》time模块为Python提供了处理时间和日期的多种功能,适用于多种与时间相关的场景,包括获取当前时间、格式化时间、暂停程序执行、计算程序运行时... 目录模块介绍使用场景主要类主要函数 - time()- sleep()- localtime()- g

如何使用 Bash 脚本中的time命令来统计命令执行时间(中英双语)

《如何使用Bash脚本中的time命令来统计命令执行时间(中英双语)》本文介绍了如何在Bash脚本中使用`time`命令来测量命令执行时间,包括`real`、`user`和`sys`三个时间指标,... 使用 Bash 脚本中的 time 命令来统计命令执行时间在日常的开发和运维过程中,性能监控和优化是不

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int