题目链接:

E. Little Artem and Time Machine

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.

Artem wants to create a basic multiset of integers. He wants these structure to support operations of three types:

  1. Add integer to the multiset. Note that the difference between set and multiset is that multiset may store several instances of one integer.
  2. Remove integer from the multiset. Only one instance of this integer is removed. Artem doesn't want to handle any exceptions, so he assumes that every time remove operation is called, that integer is presented in the multiset.
  3. Count the number of instances of the given integer that are stored in the multiset.

But what about time machine? Artem doesn't simply apply operations to the multiset one by one, he now travels to different moments of time and apply his operation there. Consider the following example.

  • First Artem adds integer 5 to the multiset at the 1-st moment of time.
  • Then Artem adds integer 3 to the multiset at the moment 5.
  • Then Artem asks how many 5 are there in the multiset at moment 6. The answer is 1.
  • Then Artem returns back in time and asks how many integers 3 are there in the set at moment 4. Since 3 was added only at moment 5, the number of integers 3 at moment 4 equals to 0.
  • Then Artem goes back in time again and removes 5 from the multiset at moment 3.
  • Finally Artyom asks at moment 7 how many integers 5 are there in the set. The result is 0, since we have removed 5 at the moment3.

Note that Artem dislikes exceptions so much that he assures that after each change he makes all delete operations are applied only to element that is present in the multiset. The answer to the query of the third type is computed at the moment Artem makes the corresponding query and are not affected in any way by future changes he makes.

Help Artem implement time travellers multiset.

Input
 

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of Artem's queries.

Then follow n lines with queries descriptions. Each of them contains three integers aiti and xi (1 ≤ ai ≤ 3, 1 ≤ ti, xi ≤ 109) — type of the query, moment of time Artem travels to in order to execute this query and the value of the query itself, respectively. It's guaranteed that all moments of time are distinct and that after each operation is applied all operations of the first and second types are consistent.

Output
 

For each ask operation output the number of instances of integer being queried at the given moment of time.

Examples
 
input
6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5
output
1
2
1
input
3
1 1 1
2 2 1
3 3 1
output
0

题意:

就是有一个时光机可以去不同的时刻对一些数值的数目进行修改;1是增加1,2是减1,3是询问;

思路:

一看就是个线段树,蓝而时间和数值的范围太大,时间可以进行离散化,数值的话那么就把线段树的节点变成map怒怼一发,我就是开开脑洞然后写写玩玩,蓝后一不小心怼过了;
哈哈哈,最近脑洞太大,经常乱搞来A题;我自己都受不了了; AC代码:
/*2014300227    669E - 33    GNU C++11    Accepted    1091 ms    78840 KB*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const ll inf=1e15;
const int N=1e5+;
int n;
struct PO
{
int a,t,va,pos;
}po[N];
int cmp1(PO x,PO y)
{
return x.t<y.t;
}
int cmp2(PO x,PO y)
{
return x.pos<y.pos;
}
struct Tree
{
int l,r;
map<int,int>mp1,mp2;
};
Tree tree[*N];
void build(int node,int L,int R)
{
tree[node].l=L;
tree[node].r=R;
if(L==R)return ;
int mid=(L+R)>>;
build(*node,L,mid);
build(*node+,mid+,R);
}
void update(int node,int pos,int num,int flag)
{
if(tree[node].l==tree[node].r&&tree[node].l==pos)
{
if(flag==)
tree[node].mp1[num]++;
else tree[node].mp2[num]++;
return ;
}
int mid=(tree[node].l+tree[node].r)>>;
if(pos<=mid)
{
update(*node,pos,num,flag);
}
else
{
update(*node+,pos,num,flag);
}
if(flag==)tree[node].mp1[num]++;
else tree[node].mp2[num]++;
}
int query(int node,int L,int R,int num,int flag)
{
if(L<=tree[node].l&&R>=tree[node].r)
{
if(flag==)return tree[node].mp1[num];
else return tree[node].mp2[num];
}
int mid=(tree[node].l+tree[node].r)>>;
if(R<=mid)
{
return query(*node,L,R,num,flag);
}
else if(L>mid)
{
return query(*node+,L,R,num,flag);
}
else
{
return query(*node,L,mid,num,flag)+query(*node+,mid+,R,num,flag);
}
}
int main()
{ scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&po[i].a,&po[i].t,&po[i].va);
po[i].pos=i;
}
sort(po+,po+n+,cmp1);
for(int i=;i<=n;i++)
{
po[i].t=i;
}
sort(po+,po+n+,cmp2);
build(,,n);
for(int i=;i<=n;i++)
{
if(po[i].a==)
{
update(,po[i].t,po[i].va,);
}
else if(po[i].a==)
{
update(,po[i].t,po[i].va,);
}
else
{ //cout<<"#"<<endl;
printf("%d\n",query(,,po[i].t,po[i].va,)-query(,,po[i].t,po[i].va,));
}
}
return ;
}

codeforces 669E E. Little Artem and Time Machine(节点为map型的线段树)的更多相关文章

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

  2. Codeforces 1175G - Yet Another Partiton Problem(李超线段树)

    Codeforces 题面传送门 & 洛谷题面传送门 这是一道李超线段树的毒瘤题. 首先我们可以想到一个非常 trivial 的 DP:\(dp_{i,j}\)​ 表示前 \(i\)​ 个数划 ...

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

  4. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  5. Educational Codeforces Round 6 E. New Year Tree dfs+线段树

    题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memo ...

  6. Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树

    C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...

  7. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  8. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  9. Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum 离线+线段树

    题目链接: http://codeforces.com/contest/703/problem/D D. Mishka and Interesting sum time limit per test ...

随机推荐

  1. python练习之-计算器

    学习以堆栈模式编写-计算器 堆栈特点:先进后出, 如下: #!/opt/python3/bin/python3 # Author: yong import re def is_symbol(eleme ...

  2. Linux使用screen实现关闭ssh连接的情况下,让程序继续在后台运行

    Ubuntu默认没有安装screen,需要手动安装. 安装命令: sudo apt-get install screen 简单的操作方法: 直接输入命令 screen 进入screen子界面,此时pu ...

  3. MFC中的双缓冲技术(解决绘图闪烁问题)

    转自 MFC绘图不闪烁——双缓冲技术[转] 在VC/MFC用CDC绘图时,频繁的刷新,屏幕会出现闪烁的现象,CPU时间占用率相当高,绘图效率极低,很容易出现程序崩溃. 所谓双缓冲技术,下面是百度百科的 ...

  4. 数字巨头们的表态--<大佬与大话>

    作者魏武挥 类别非虚构 / 中篇 本书为作者为<21世纪商业评论>的专栏文章合集,共20篇,算是第一卷吧,后期还会写下去.这个专栏的名字叫<大佬与大话>,专门收集TMT圈子商业 ...

  5. python 工具ScreenShoot

    环境:windows python3 # -*- coding: UTF-8 -*- import time import os, win32gui, win32ui, win32con, win32 ...

  6. 赵雅智_Swift(2)_swift常量和变量

    分号 Swift 并不强制要求你在每条语句的结尾处使用分号(;) 你打算在同一行内写多条独立的语句必需要用分号 let cat = "? ?? ? "; println(cat) ...

  7. POJ3420 Quad Tiling DP + 矩阵高速幂

    题目大意是用1*2的骨牌堆积成4*N的矩形.一共同拥有多少种方法,N不超过10^9. 这题和以前在庞果网上做过的一道木块砌墙差点儿一样. 由于骨牌我们能够横着放.竖着放.我们如果以4为列,N为行这样去 ...

  8. Yii Criteria常用方法(select,join,where,日期,)

    $criteria = new CDbCriteria;  //select $criteria->select = '*';//默认* $criteria->select = 'id,n ...

  9. 面向对象 委托变量和this的使用

    委托方法: this的使用:

  10. C++模板实现的AVL树

    1 AVL树的定义 AVL树是一种自平衡二叉排序树.它的特点是不论什么一个节点的左子树高度和右子树的高度差在-1,0,1三者之间. AVL树的不论什么一个子树都是AVL树. 2 AVL树的实现 AVL ...