题目链接:http://acm.uestc.edu.cn/#/problem/show/1059

普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真是个沙茶……

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(LL i = 0; i < (len); i++)
#define For(i, a, len) for(LL i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
typedef long long LL; const int maxn = ;
LL sum[maxn<<];
LL add[maxn<<];
int n, m;
int hcnt;
LL h[maxn];
LL cmd[maxn], a[maxn], b[maxn], c[maxn]; void pushUP(int rt) {
sum[rt] = sum[lrt] + sum[rrt];
} void pushDOWN(int rt, int m) {
if(add[rt]) {
add[lrt] += add[rt];
add[rrt] += add[rt];
sum[lrt] += (m - (m >> )) * add[rt];
sum[rrt] += (m >> ) * add[rt];
add[rt] = ;
}
} void build(int l, int r, int rt) {
add[rt] = sum[rt] = ;
if(l == r) return;
int m = (l + r) >> ;
build(l, m, lrt);
build(m+, r, rrt);
pushUP(rt);
} void update(int L, int R, int x, int l, int r, int rt) {
if(l >= L && R >= r) {
add[rt] += x;
sum[rt] += (r - l + ) * x;
return;
}
pushDOWN(rt, r-l+);
int m = (l + r) >> ;
if(m >= L) update(L, R, x, l, m, lrt);
if(m < R) update(L, R, x, m+, r, rrt);
pushUP(rt);
} LL query(int p, int l, int r, int rt) {
if(l == r && p == l) return sum[rt];
pushDOWN(rt, r-l+);
int m = (l + r) >> ;
if(p <= m) {
LL ret = query(p, l, m, lrt);
pushUP(rt);
return ret;
}
else {
LL ret = query(p, m+, r, rrt);
pushUP(rt);
return ret;
}
} int getid(int x) {
return lower_bound(h, h+hcnt, x) - h + ;
} int main() {
// FRead();
while(~Rint(n) && ~Rint(m)) {
hcnt = ;
Rep(i, m) {
Rint(cmd[i]);
if(cmd[i] == ) {
Rll(a[i]); Rll(b[i]); Rll(c[i]);
h[hcnt++] = a[i]; h[hcnt++] = b[i];
}
if(cmd[i] == ) {
Rll(a[i]);
h[hcnt++] = a[i];
}
}
sort(h, h+hcnt); hcnt = unique(h, h+hcnt) - h;
build(, hcnt, );
Rep(i, m) {
if(cmd[i] == ) update(getid(a[i]), getid(b[i]), c[i], , hcnt, );
if(cmd[i] == ) printf("%lld\n", query(getid(a[i]), , hcnt, ));
}
}
return ;
}

[UESTC1059]秋实大哥与小朋友(线段树, 离散化)的更多相关文章

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

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

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

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

  3. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  4. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  5. UESTC-1057 秋实大哥与花(线段树+成段加减+区间求和)

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

  6. UESTC - 1057 秋实大哥与花 线段树

    题意 秋实大哥是一个儒雅之人,昼听笙歌夜醉眠,若非月下即花前. 所以秋实大哥精心照料了很多花朵.现在所有的花朵排成了一行,每朵花有一个愉悦值. 秋实大哥每天要对着某一段连续的花朵歌唱,然后这些花朵的愉 ...

  7. 2015 UESTC 数据结构专题B题 秋实大哥与花 线段树 区间加,区间查询和

    B - 秋实大哥与花 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  8. UESTC 1061 秋实大哥与战争 线段树区间合并

    秋实大哥与战争 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 男儿何不带吴钩, ...

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

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

随机推荐

  1. div+css登陆界面案例2

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

    Demo地址:https://github.com/chenfanfang/CollectionsOfExampleFFDropDownMenu框架地址:https://github.com/chen ...

  3. 关于JS的一些代码效果图

    关于JS的一些代码效果图 1.几乎所有DOM元素都有innerText.innerHTML属性(注意大小写),分别是元素标签内内容的文本表示形式和HTML源代码,这两个属性是可读可写的. 需要注意的是 ...

  4. C# mongodb [上]

    概述 MongoDB是一个高性能,开源,无模式的文档型数据库,使用C++开发.是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是 ...

  5. 【HDOJ】【2089】不要62

    数位DP cxlove基础数位DP第一题 用容斥把所有的不吉利数字去掉就得到吉利数字的数量= =(满足区间减法) //HDOJ 2089 #include<cmath> #include& ...

  6. What are Scopes?

    scope is an object that refers to the application model. It is an execution context for expressions. ...

  7. [转载]Spring Bean Configuration Inheritance

    转自: http://www.mkyong.com/spring/spring-bean-configuration-inheritance/ In Spring, the inheritance i ...

  8. 【leetcode】Combination Sum (middle)

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  9. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  10. jQuery动画效果实现

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...