Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu

Appoint description: 
System Crawler  (2016-04-23)

Description

秋实大哥以周济天下,锄强扶弱为己任,他常对天长叹:安得广厦千万间,大庇天下寒士俱欢颜。

所以今天他又在给一群小朋友发糖吃。

他让所有的小朋友排成一行,从左到右标号。在接下去的时间中,他有时会给一段区间的小朋友每人$v$颗糖,有时会问第$x$个小朋友手里有几颗糖。

这对于没上过学的孩子来说实在太困难了,所以你看不下去了,请你帮助小朋友回答所有的询问。

Input

第一行包含两个整数$n$,$m$,表示小朋友的个数,以及接下来你要处理的操作数。

接下来的$m$行,每一行表示下面两种操作之一:

0 l r v : 表示秋实大哥给[l,r]这个区间内的小朋友每人v颗糖

1 x : 表示秋实大哥想知道第x个小朋友手里现在有几颗糖

$1\leq m, v\leq 100000$,$1\leq l\leq r\leq n$,$1\leq x\leq n$,$1\leq n\leq 100000000$。

Output

对于每一个$1$ $x$操作,输出一个整数,表示第$x$个小朋友手里现在的糖果数目。

Sample Input

3 4 
0 1 3 1 
1 2 
0 2 3 3 
1 3

Sample Output

1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int maxn=100000;
ll tri[2*maxn+10];
int n,m;
set<int> judge;
vector<int> point; struct Ope{
int op,l,r,v,pos;
}; int lowbit(int i)
{
return i&(-i);
} ll query(int pos)
{
ll sum=0;
while(pos<=point.size())
{
sum+=tri[pos];
pos+=lowbit(pos);
}
return sum;
}//区间更新中的单点查询 void update(int l,int r,int v)
{
while(r>0)
{
tri[r]+=v;
r-=lowbit(r);
}
int k=l-1;
while(k>0)
{
tri[k]-=v;
k-=lowbit(k);
}
}//区间更新 int main()
{
while(~scanf("%d %d",&n,&m))
{
queue<Ope> opq;
judge.clear();
point.clear();
MM(tri,0); for(int k=1;k<=m;k++)
{
int w,l,r,v,pos;
scanf("%d",&w);
if(w==0)
{
scanf("%d %d %d",&l,&r,&v);
if(!judge.count(l))
{
judge.insert(l);
point.push_back(l);
}
if(!judge.count(r))
{
judge.insert(r);
point.push_back(r);
}
opq.push((Ope){0,l,r,v,0});
}
else
{
scanf("%d",&pos);
if(!judge.count(pos))
{
judge.insert(pos);
point.push_back(pos);
}
opq.push((Ope){1,0,0,0,pos});
}
} sort(point.begin(),point.end());//用point来离散化
while(opq.size())
{
Ope cur=opq.front();opq.pop();
if(cur.op==1)
{
int pos=lower_bound(point.begin(),point.end(),cur.pos)-point.begin()+1;
printf("%lld\n",query(pos));
}//pos代表离散化后在BIT中的位置
else
{
int l=lower_bound(point.begin(),point.end(),cur.l)-point.begin()+1;
int r=lower_bound(point.begin(),point.end(),cur.r)-point.begin()+1;
update(l,r,cur.v);
}
}
}
return 0;
}

  1:set可以用来判重judge.count(判断元素的值),但是不能对其进行迭代器的加减法;

set的使用文章链接

2:对要进行操作的点进行离散化;

3:BIT区间更新+单点查询

CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询的更多相关文章

  1. UESTC 1059 - 秋实大哥与小朋友

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 Time Limit: 3000/1000MS (Java/Others)     Memory Li ...

  2. UESTC_秋实大哥与小朋友 2015 UESTC Training for Data Structures<Problem A>

    A - 秋实大哥与小朋友 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  3. 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化

    秋实大哥与小朋友 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...

  4. UESTC-1059 秋实大哥与小朋友(离散化+线段树)

    秋实大哥与小朋友 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  5. CDOJ 1061 C - 秋实大哥与战争 STL set 迭代器

    题目链接: C - 秋实大哥与战争 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Sub ...

  6. CDOJ 1069 秋实大哥去打工 单调栈 下标处理

    E - 秋实大哥去打工 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit St ...

  7. CDOJ 1070 秋实大哥打游戏 带权并查集

    链接 F - 秋实大哥打游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  8. CDOJ 1060 秋实大哥与快餐店 字典树 水题

    题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Sub ...

  9. CDOJ 1057 秋实大哥与花 线段树 区间更新+区间查询

    链接: I - 秋实大哥与花 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. Java学习开发第一阶段总结

    前言: 按照学院的安排我专业应该在下学期学习Java课程,因为对技术的热爱,我选择了在本学期学习Java.俗话说得好“笨鸟先飞”,那我就先学习这门课程了. 第一阶段的学习总结: 在此次阶段任务相对比较 ...

  2. Being a Good Boy in Spring Festival

    Being a Good Boy in Spring Festival Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一 ...

  3. 三校联训 小澳的葫芦(calabash) 题解

    题面:小澳的葫芦[ 题目描述]小澳最喜欢的歌曲就是<葫芦娃>.一日表演唱歌,他尽了洪荒之力,唱响心中圣歌.随之,小澳进入了葫芦世界.葫芦世界有 n 个葫芦,标号为 1~ n. n 个葫芦由 ...

  4. MongoDB和Redis的区别

    1).内存管理机制 a.Redis的数据全部存储在内存当中,会定期写入到磁盘当中,当内存不够用时, 可以选择指定的LRU(最近最少使用算法)的算法删除数据: b.MongoDB数据存在内存,有Linu ...

  5. Centos7搭建FTP服务

    1.安装 vsftpd ​[root@CentOS ftp]# yum -y install vsftpd2.启动 vsftpd 服务 ​[root@CentOS ~]# systemctl star ...

  6. Timetable CodeForces - 946D (区间dp)

    大意: n天, 每天m小时, 给定课程表, 每天的上课时间为第一个1到最后一个1, 一共可以逃k次课, 求最少上课时间. 每天显然是独立的, 对每天区间dp出逃$x$次课的最大减少时间, 再对$n$天 ...

  7. vim学习(三)之命令

    参考 Linux vi/vim vim常用命令总结

  8. php引用 & 详解

    在PHP 中引用的意思是:不同的名字访问同一个变量内容. 与C语言中的指针是有差别的.C语言中的指针里面存储的是变量的内容在内存中存放的地址 变量的引用 $a = 222; $b = &$a; ...

  9. Python3零基础入门学习视频+源码+课件+习题-小甲鱼

    目录 1. 介绍 2. 目录 3. 下载地址 1. 介绍 适用人群 完全零基础入门,不需要任何前置知识. 课程概述 本系列教程面向零基础的同学,是一个深入浅出,通俗易懂的Python3视频教程. 前半 ...

  10. Windows下搭建Nacos及Seata

    一.简介 本文主要描述Nacos及Seata在Windows环境下环境搭建 下载相关软件: Nacos-1.1.4 Seata-0.9.0 二.安装 2.1安装Nacos 解压nacos-server ...