CodeForces 669E Little Artem and Time Machine
树状数组,$map$。
可以理解为开一个数组$f[i][j]$记录:$i$这个数字在时间$j$的操作情况。
操作$1$:$f[x][t]++$。操作$2$:$f[x][t]--$。操作$3$:$f[x][1]$至$f[x][t]$求和。
数组开不出来,但可以开$map$,状态最多$100000$个,所以还是不会超时的,数字范围有点大,可以离散化一下。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int n,op[maxn],t[maxn],x[maxn];
map<int,int>c[maxn];
int T[maxn],X[maxn]; int lowbit(int x){ return x&(-x); } void update(int p,int q,int v)
{
for(int i=q;i<=n;i=i+lowbit(i))
c[p][i]+=v;
} int sum(int p,int q)
{
int res=;
for(int i=q;i>;i=i-lowbit(i))
res+=c[p][i];
return res;
} int get(int x)
{
int L=,R=n,pos;
while(L<=R)
{
int m=(L+R)/;
if(X[m]>x) R=m-;
else if(X[m]<x) L=m+;
else pos=m,R=m-;
}
return pos;
} int g(int x)
{
int L=,R=n,pos;
while(L<=R)
{
int m=(L+R)/;
if(T[m]>x) R=m-;
else if(T[m]<x) L=m+;
else pos=m,R=m-;
}
return pos;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&op[i],&t[i],&x[i]);
T[i]=t[i]; X[i]=x[i];
}
sort(T+,T++n); sort(X+,X++n);
for(int i=;i<=n;i++)
{
if(op[i]==) update(get(x[i]),g(t[i]),);
else if(op[i]==) update(get(x[i]),g(t[i]),-);
else printf("%d\n",sum(get(x[i]),g(t[i])));
}
return ;
}
CodeForces 669E Little Artem and Time Machine的更多相关文章
- 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 ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- 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 事情是按 ...
- CodeForces669E:Little Artem and Time Machine(CDQ分治)(或者用map+树状数组优美地解决)
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of cour ...
- codeforces 442C C. Artem and Array(贪心)
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CodeForces - 669D Little Artem and Dance 想法题 多余操作
http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...
- CodeForces 668B Little Artem and Dance
B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...
- codeforces 668C - Little Artem and Random Variable
题目链接:http://codeforces.com/contest/668/problem/C --------------------------------------------------- ...
随机推荐
- 线程:ThreadLocal实现线程范围内共享变量
在web应用中,一个请求(带有请求参数)就是一个线程,那么如何区分哪些参数属于哪个线程呢?比如struts中,A用户登录,B用户也登录,那么在Action中怎么区分哪个是A用户的数据,哪个是B用户的数 ...
- c# UDP/TCP协议简单实现(简单聊天工具)
长时间没有摸这两个协议,写个代码温习下 下面是界面 [服务器界面] [登陆界面] [好友列表界面(我登陆了2个)] [聊天界面] 下面大致讲解下用到的内容 1.用户登陆于服务器通信用到的tcp协议,服 ...
- Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例
Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例 一.在Eclipse下编译安装Hadoop插件 Hadoop的Eclipse插件现在已经没有二进制版直接提供,只能自己编译. ...
- ASP.NET MVC 之Model的呈现
ASP.NET MVC 之Model的呈现(仅此一文系列三) 本文目的 我们来看一个小例子,在一个ASP.NET MVC项目中创建一个控制器Home,只有一个Index: public class H ...
- IP地址分类(转)
IP地址分类以及C类IP地址的子网划分 国际规定:把所有的IP地址划分为 A,B,C,D,E A类地址:范围从0-127,0是保留的并且表示所有IP地址,而127也是保留的地址,并且是用于测试环回用的 ...
- asp.net mvc Route 使用自定义条件(constraints)禁止某ip登陆
asp.net mvc Route 使用自定义条件(constraints)禁止某ip登陆 前言 本文的目的是利用Mvc route创建一个自定义约束来控制路由跳转实现禁止ip登陆,当然例子可能不合理 ...
- ios学习笔记(一)之Object-C
一:Objective-C语言基础 二:Objective-C类与继承和协议 一:Objective-C语言基础: 1.1)#import 包含头文件 与#include 作用相同 1.2)Obje ...
- 微信移动端web页面调试小技巧
技术贴还是分享出来更加好,希望能对一些朋友有帮助,个人博客 http://lizhug.com/mymajor/微信移动端web页面调试小技巧
- SSH使用技巧
SSH使用技巧 SSH免输入密码 原理是依赖证书去认证,从而免除密码输入. 通过ssh-keygen生成一对公私钥,是否使用passphrase可以根据个人喜好.(其实使用证书就是为了方便而已,我是不 ...
- shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)
shell脚本兼容linux/unix与windows/cygwin的基础 :统一文本格式为:unix文本格式,即于LF为换行符(推荐方案) 在notepad上设置:编辑->档案格式转换-> ...