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. 【czy系列赛】czy的后宫6 && bzoj1044 [HAOI2008]木棍分割

    题目描述 众所周知的是丧尸czy有很多妹子(虽然很多但是质量不容乐观QAQ),今天czy把n个妹子排成一行来检阅.但是czy的妹子的质量实在--所以czy看不下去了.检阅了第i个妹子会增加czy a[ ...

  2. cf448B Suffix Structures

    B. Suffix Structures time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. UESTC_小panpan学图论 2015 UESTC Training for Graph Theory<Problem J>

    J - 小panpan学图论 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) S ...

  4. LeetCode C++ 解题报告

    自己做得LeetCode的题解,使用C++语言. 说明:大多数自己做得,部分参考别人的思路,仅供参考; GitHub地址:https://github.com/amazingyyc/The-Solut ...

  5. dp优化

    入口 A(fzu 1894) 普通的单调队列,trick是进队判断的符号选取(>=wa , >ac). B(poj 2823) 没什么好说的 ,坑爹poj g++,tle ;c++,ac. ...

  6. ListView之BaseAdapter

    BaseAdapter可以实现自定义的丰富子项视图,本文实现如下所示结果: 实现代码: /* ListView :列表 BaseAdapter 通用的基础适配器 * * */ public class ...

  7. iOS获取一个方法的执行时间

    #import <Foundation/Foundation.h> #import <mach/mach_time.h> typedef void (^block)(void) ...

  8. Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办

    Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办 跟个磁盘队列长度雅十,一到李80%走不行兰.... 1. 寻找线程too 多的.关闭... Taskman>> ...

  9. SQL 2008存储图片和读取图片

    用SQL Server存储文字数据非常easy实现,假设用SQL Server存储图片呢?大家有没有实现思路呢?如今我用一个Demo来为大家提供一种在SQL Server中存储图片的思路. 场景:在s ...

  10. 设置 git config 的一些默认配置

    设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...