树状数组,$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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  4. 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 事情是按 ...

  5. 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 ...

  6. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  8. 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 ...

  9. codeforces 668C - Little Artem and Random Variable

    题目链接:http://codeforces.com/contest/668/problem/C --------------------------------------------------- ...

随机推荐

  1. 使用WCF扩展记录服务调用时间

    随笔- 64  文章- 0  评论- 549  真实世界:使用WCF扩展记录服务调用时间   WCF 可扩展性 WCF 提供了许多扩展点供开发人员自定义运行时行为. WCF 在 Channel Lay ...

  2. SL.XNA中的Popup

    如果要xna与sl混合显示,就不能用popup,不然会有各种显示错乱的问题.如果xna与sl单独显示,可以使用popup,但是要记得移除UIElementRenderer.就是说popup只能交给系统 ...

  3. Mac下chrome的webapp hostadmin 快速切换host

    首先是安装 app ,https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg ...

  4. Mongodb 集群搭建以及常见错误

    Mongodb 集群搭建以及常见错误 1 关于Replica Sets +Sharding(主从复制加分片)搭建,不这详细去说,网上有很多,大部分的例子就三台服务器之间做主从复制,分2个shard,架 ...

  5. 当Erlang遇到Solr

    当Erlang遇到Solr   Joe Armstrong的访谈中有一段关于"打开黑盒子"的阐述,给我留下很深的印象:Joe Armstrong在做XWindows开发时没有使用对 ...

  6. Dispose模式

    Dispose模式 Dispose模式是.NET中很基础也很重要的一个模式,今天重新复习一下相关的东西并记录下来. 什么是Dispose模式? 什么时候我们该为一个类型实现Dispose模式 使用Di ...

  7. #2006 - MySQL server has gone away 问题解决方法 (全) (转)

    #2006 - MySQL server has gone away 问题解决方法 原文地址:http://www.cnblogs.com/bisonjob/archive/2009/08/18/15 ...

  8. Call U

    Communication - 02.Call U App层 从大拇哥Click CallButton开始手机便已明白,主人这是要打电话.当然,你可以选择直接拨号,也可以通过ContactList,或 ...

  9. Extjs4.2 Tree使用技巧

    Extjs4.2 Tree使用技巧小结demo 本案例使用了Ext.Tree.Panel的如下知识点: 1.刷新.重新加载Tree,定位到上次的节点位置 2.Tree的右键操作 3.Extjs4.x ...

  10. HDU--杭电--3415--Max Sum of Max-K-sub-sequence--队列--双向队列

    Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...