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 --------------------------------------------------- ...
随机推荐
- boke
云/n 计算/v 代表/n IT/x 领域/n 向/p 集约化/v ./w 规模化/v 与/c 专业化/v 道路/n 发展/v 的/u 趋势/n ,/w 是/v IT/x 领域/n 正在/d 发生/v ...
- Solr与MongoDB集成,实时增量索引
Solr与MongoDB集成,实时增量索引 一. 概述 大量的数据存储在MongoDB上,需要快速搜索出目标内容,于是搭建Solr服务. 另外一点,用Solr索引数据后,可以把数据用在不同的项目当中, ...
- WPF专业编程指南 - 那些根元素<>的解释
<Window x:Class="Chapter1_WpfApplication1.MainWindow" xmlns="http://schemas.micros ...
- SecureCRT退出全屏方法
今天在使用SecureCRT的过程中,无意点了全屏,导致SecureCRT连接某台服务器的seesion全屏.后来想退出全屏,SecureCRT没有任何提示,上网查了一下资料说: 退出全屏的命令是AL ...
- Android Widget(窗口小部件)
Android Widget简介 应用程序窗口小部件(Widget)是微型的应用程序视图,它可以被嵌入到其它应用程序中(比如桌面)并接收周期性的更新.你可以通过一个App Widget Provide ...
- jQuery.fn.attr与jQuery.fn.prop
jQuery.fn.attr与jQuery.fn.prop jQuery.fn.attr.jQuery.fn.prop的区别 假设页面有下面这么个标签,$('#ddd').attr('nick').$ ...
- C#基础原理拾遗——引用类型的值传递和引用传递
C#基础原理拾遗——引用类型的值传递和引用传递 以前写博客不深动,只搭个架子,像做笔记,没有自己的思考,也没什么人来看.这个毛病得改,就从这一篇开始… 最近准备面试,深感基础之重要,奈何我不是计算机科 ...
- C语言中判断int,long型等变量是否赋值的方法
博主这段时间在写一些C程序的代码,由于以前对C不是了解很多,故遇到很多瓶颈,当然,其中也有很多有趣的方法可以利用以解决这些难题,下面这个问题就是博主遇到的一个麻烦. 声明了 int ,long 型等局 ...
- MTD设备驱动
MTD(memory technology device):内存技术设备 是linux用于描述ROM,NAND,NOR等内存设备的子系统的抽象 MTD设备可以按块读写也可以按字节读写,也就是说MTD设 ...
- react+redux渲染性能优化原理
大家都知道,react的一个痛点就是非父子关系的组件之间的通信,其官方文档对此也并不避讳: For communication between two components that don't ha ...