A - 秋实大哥与小朋友

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

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

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

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

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

Input

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

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

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

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

1≤m,v≤100000,1≤l≤r≤n,1≤x≤n,1≤n≤100000000。

Output

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

Sample input and output

Sample Input Sample Output
3 4
0 1 3 1
1 2
0 2 3 3
1 3
1
4

解题报告

首先由于小朋友数目可以高达1e8,因此我们首先读入所有点,离散化..

之后上线段树还是上树状数组就随意了。。

我是采用的树状数组..这里我的离散化写的水,每次都要二分查位置(好吧,不要在意这些细节)

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
int size;
set<int>cv;
int point[maxn]; typedef struct oper
{
int l,r,v,ope;
oper(const int &ope, const int &l,const int &r,const int &v)
{
this->ope = ope , this->l = l , this->r = r , this->v = v;
}
}; queue<oper>query;
ll c[maxn]; inline int lowbit(int cur)
{
return cur&(-cur);
} void add(int l,ll v)
{
if (!l)
return;
while(l > )
{
c[l] += v;
l -= lowbit(l);
}
} ll find(int x)
{
ll res = ;
while(x <= size)
{
res += c[x];
x += lowbit(x);
}
return res;
} int main(int argc,char *argv[])
{
memset(c,,sizeof(c));
int n,m;
scanf("%d%d",&n,&m);
size = ;
while(m--)
{
int ope;
scanf("%d",&ope);
if (ope & )
{
int temp;
scanf("%d",&temp);
if (!cv.count(temp))
{
cv.insert(temp);
point[++size] = temp;
}
query.push(oper(ope,,,temp));
}
else
{
int l,r,v;
scanf("%d%d%d",&l,&r,&v);
if (!cv.count(l))
{
cv.insert(l);
point[++size] = l;
}
if (!cv.count(r))
{
cv.insert(r);
point[++size] = r;
}
query.push(oper(ope,l,r,v));
}
}
sort(point+,point++size);
while(!query.empty())
{
oper ss = query.front();query.pop();
if (ss.ope & )
{
int pos = lower_bound(point+,point+size,ss.v) - point;
printf("%lld\n",find(pos));
}
else
{
ll v = (ll)ss.v;
int pos = lower_bound(point+,point+size,ss.l) - point;
add(pos-,-v);
pos = lower_bound(point+,point+size,ss.r) - point;
add(pos,v);
}
}
return ;
}

UESTC_秋实大哥与小朋友 2015 UESTC Training for Data Structures<Problem A>的更多相关文章

  1. UESTC_秋实大哥搞算数 2015 UESTC Training for Data Structures<Problem N>

    N - 秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  2. UESTC_秋实大哥打游戏 2015 UESTC Training for Data Structures<Problem H>

    H - 秋实大哥打游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  3. UESTC_秋实大哥去打工 2015 UESTC Training for Data Structures<Problem G>

    G - 秋实大哥去打工 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  4. UESTC_秋实大哥与家 2015 UESTC Training for Data Structures<Problem E>

    E - 秋实大哥与家 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  5. UESTC_秋实大哥与战争 2015 UESTC Training for Data Structures<Problem D>

    D - 秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  6. UESTC_秋实大哥与快餐店 2015 UESTC Training for Data Structures<Problem C>

    C - 秋实大哥与快餐店 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  7. UESTC_秋实大哥与花 2015 UESTC Training for Data Structures<Problem B>

    B - 秋实大哥与花 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  8. UESTC_秋实大哥掰手指 2015 UESTC Training for Dynamic Programming<Problem B>

    B - 秋实大哥掰手指 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 2048/1024KB (Java/Others) Submit ...

  9. UESTC_秋实大哥与线段树 2015 UESTC Training for Data Structures<Problem M>

    M - 秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

随机推荐

  1. 【剑指offer】面试题26:复杂链表的复制

    题目: 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点). 思路: 复制自身到下一个结点: 设置新结点的random指针: 分离链表. 注意:判 ...

  2. Java连接Oracle数据库的示例代码

    最基本的Oracle数据库连接代码(只针对Oracle11g): 1.右键项目->构建路径 ->配置构建路径,选择第三项“库”,然后点击“添加外部Jar”,选择 “D:\Oracle\ap ...

  3. (史上最全的ios源码汇总)

    按钮类         按钮 Drop Down Control         http://www.apkbus.com/android-106661-1-1.html 按钮-Circular M ...

  4. Guice 学习(六)使用Provider注入服务( Provider Inject Service)

    1.定义接口 package com.guice.providerInject; import com.google.inject.ProvidedBy; public interface Servi ...

  5. 【iOS开发-66】QQ设置界面的案例:利用storyboard开发静态的tableView界面,核心是Static Cells

    (1)效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2Vpc3ViYW8=/font/5a6L5L2T/fontsize/400/fill/I0JB ...

  6. [React] Styling a React button component with Radium

    React's inline styles allow components to stand on their own by not requiring any external CSS. Howe ...

  7. .NET中反射机制的使用与分析

    .NET中反射机制的使用与分析 [日期:2008-06-30] 来源:  作者:志伟     .NET反射的定义:审查元数据并收集关于它的类型信息的能力. 元数据是一种二进制信息,用以对存储在公共语言 ...

  8. 图片轮播插件 Slides-SlidesJS-3

    图片轮播插件  Slides-SlidesJS-3 demo document 地址: http://slidesjs.com/

  9. angular的数据双向绑定秘密

    Angular用户都想知道数据绑定是怎么实现的.你可能会看到各种各样的词汇:$watch,$apply,$digest,dirty-checking... 它们是什么?它们是如何工作的呢?这里我想回答 ...

  10. Dreamwaver 使用root用户连接不上远程服务器

    我用dreamweaver连接远程服务,开始用的是root用户登录的,但是连接不上.网上查了一下,解决教程非常复杂,我就不列出来了. 后来我想了一下,之前我有连接过.我感觉可能是用户的问题,于是我在远 ...