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. C# 知识点收集

    1. 数组复制 byte[] source; byte[] dest; int srcOffset = 0; int dstOffset = 0; int count = 10; System.Buf ...

  2. UML建模工具-火龙果软件

     官网地址:http://code.uml.com.cn/index.asp     Bridge桥梁模式    (待逆向) 桥梁模式,通过增加一个类,将抽象部分与它的实现部分分离,使它们都可以独立 ...

  3. Majority Element II 解答

    Question Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Th ...

  4. Mysql日期函数,时间函数使用的总结

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now();+--------------------- ...

  5. CreateFile使用方法和样例

    函数原型: HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名称的指针 DWORD dwDesiredAccess, //訪问模式(写/读) DWORD dw ...

  6. CCS v5 无法启动解决办法及Launchpad仿真器电脑无法识别解决方法

    安装ccs_setup_5.1.1.00028.exe后(无论是自己装eclipse还是在原来的基础上安装eclipse的插件),ccs5的应用无法打开,错误为:An error has occurr ...

  7. keycode(来自互联网)

  8. javascript 阻止事件冒泡和阻止默认事件对比

    公司项目有像上图中效果的功能需求这也是很常见功能很简单功能,通过一个小例子和大家聊聊js的事件冒泡和默认事件. 先说说一般的实现方式即使用阻止事件冒泡的方式去做,给input绑定一个click事件(并 ...

  9. OpenCV——无法启动此程序,丢失**解决办法

    OpenCV程序运行时,有时出现以下错误: 解决方法: 在opencv安装目录下找到这个链接库,将其复制到以下指定目录中 我的链接库目录为:E:\Program files\opencv\build\ ...

  10. Niagara AX之BajaScript资料哪里找

    四个步骤:(开篇:多谢陈工!) 1.Services下添加box->boxService: 2.在Apps下添加BajaScriptTutorialsApp: 3.登录用户的Web Profil ...