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. < welcome > 一起学习,进步,分享。

    现在时间:2014-3-24 hello world my blog. 第一次做博客,欢迎各路朋友指教.慢慢的分享学习到得东西,本人目前正在做IOS,也在学习数据库简单地应用. 作为一个IOS开发者, ...

  2. mysql 中文配置(转)

    Dos下连接mysql后,运行一下几项就可以插入中文了: SET character_set_client = gbk; SET character_set_connection = gbk; SET ...

  3. jsp页面判断文件上传类型

    <script language="javascript" type="text/javascript"> function check_file( ...

  4. MySql 中的常见问题解决方法

    一.关键字做字段 ,mssql的做法是[关键字],mysql的做法是 `关键字` ;ps:(` 是 tab键上面的一个按键) 二.mssql数据导入到mysql: 1.mssql导出insert语句( ...

  5. MySql命令——命令行客户机的分隔符

    delimiter // create procedure productpricint() begin select avg(price) as priceaverage from product; ...

  6. AngularJS Directive - 开场小介绍(转)

    Directive其实就是让html变得更强大的一种方法.它可以根据需求对dom变形,或注入行为. 觉得它很神秘么,其实一点儿也不神秘,只要开始使用AngularJS了,就一定在使用着Directiv ...

  7. ServiceAccount 枚举

    指定服务的安全上下文,安全上下文定义其登录类型. 命名空间:  System.ServiceProcess程序集:  System.ServiceProcess(在 System.ServicePro ...

  8. Android5.0+(CollapsingToolbarLayout)

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

  9. Java---文件夹及文件操作

    /** * 获取文件夹大小 * @param file File实例 * @return long */ public static long getFolderSize(java.io.File f ...

  10. Cisco cmd 命令

    1.enable 开启全局配置模式:disable 禁用配置模式 2.config进入配置模式 3.line 设置进入用户模式密码:分为 line aux 0;line console 0;line ...