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 ...
- [原]关于在 iOS 中支持 DLNA
目前国内的视频播放器中,支持 DLNA 播放比较好的是:腾讯视频. 刚才反编了一下他们的代码,发现使用了一个开源库, 地址:https://github.com/FuruyamaTakeshi/DLN ...
- SolrCloud攻略
SolrCloud攻略 近期一直在使用SolrCloud,乘着酒醉大概总结一下. 1.安装 原来一直有个误区,认为SolrCloud启动时,必须至少有个core才可以,其实不然. 首先按照Solr官方 ...
- EasyUI 1.3.6 DateBox添加清空按钮
EasyUI 1.3.6 DateBox添加清空按钮 效果如图: EasyUI datebox是没有清空按钮的,可通过如下方法加入: 打开jquery.easyui.min.js看到这样如此乱的代码, ...
- 搜索广告与广告网络Demand技术-搜索广告
搜索广告 搜索广告就是一个典型的Ad Network,但是搜索广告非常重要,它的收入非常高,所以它有其独特之处,复杂度也比展示广告要高.它与展示广告在点击率预测,检索部分差不多,它的特点:1. 用户定 ...
- 利用ie的behavior属性兼容css3的一些属性
behavior是从Internet Explorer 5开始引入的,是一种通过使用 CSS 向 HTML 元素添加行为的方法. 但是只有 Internet Explorer 支持 behavior ...
- 采用SOLR进行全文索引的完整解决方案,设计图
- openssh6.7.deb download packed for debian7/ubuntu12.04 amd64
openssh the openssh-server on debian7/ubuntu12.04 is too old and out of date. so now we replace and ...
- [每日一题] OCP1z0-047 :2013-07-19 Rules of Precedence――括号的使用
这道题目的意思是你的公司决定给所有呆到5年或5年以上的所有员工每个月加50美元,然后算出总的年薪.每个月薪水:salary,每个月加到:salary+50,总的年薪: (salary+50)*12. ...
- 直插式精巧I/O模块:WIZ812MJ数据手册V1.1
1. 简介 WIZ812MJ是一款内嵌了W5100(硬件TCP/IP芯片,内置PHY).带其他胶合逻辑的MAG-JACK(带变压器的RJ45)网络模块.它可以当作一个组件使用,而且不需要为W5100和 ...