题目链接:

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. OO第三单元作业小结

    一.JML理论基础及应用工具链情况 理论基础 1.JML表达式 \result:表示方法执行后的返回值. \old(expr):表示一个表达式expr在相应方法执行前的取值. \foall:全称量词修 ...

  2. poi 读取excel row.getCell() 为null

    ##### getCell()为null 科目 余额 1 利息 1000 2 60 3 现金 10000 表格第一个单元为空时getCell()为null,直接使用会出现空指针异常

  3. IO 函数

    http://www.cnblogs.com/orange1438/p/4613460.html

  4. js正則表達式:验证邮箱格式、password复杂度、手机号码、QQ号码

    $(function () { $("input[name='sub']").on("click", function () { if (!isEmail($( ...

  5. java平台利用jsoup开发包,抓取优酷视频播放地址与图片地址等信息。

    /********************************************************************************************  * aut ...

  6. gulp配置 - PC

    初始化目录结构如下(图片看不清可以拖到桌面或者直接CTRL+鼠标滚轮进行观看) 开发环境示例: 上线环境示例: gulpfile.js(详解版) (2018-3-28)添加了scss处理(去除了les ...

  7. 【转载】回调函数(callback)是什么?

    一个很形象的例子: 你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货.在这个例子里,你的电话号码就叫回 ...

  8. Intel Naming Strategy--1

    http://en.wikipedia.org/wiki/Mobile_Internet_device Computer sizes   Classes of computers   Larger S ...

  9. const成员函数总结

    const 成员函数: 类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态数据成员)作不论什么改变. 在设计类的时候.一个原则就是对于不改变数据成员的成员函数都要 ...

  10. Appium,IOS 模拟器,Java工程搭建

    首先进入sample code Test App 有TestApp.xcodeproj文件的工程目录下 下编译出TestApp.app文件 1.新建 java 工程 2.import需要的包 新建cl ...