卿学姐与基本法

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

“做专题也要按照基本法”

离开了诡异的村庄,卿学姐来到了威廉·圣·乱七八糟王国,这里的国王咸鱼王是个智障。

国家涣散,盗贼四起,民不聊生。

见到这样的景象,卿学姐不禁潸然泪下,“悠悠苍天,奈何苦了苍生”。

自幼学习基本法的卿学姐决定向整个国家普及基本法,改善国家法度。

在这个国家总共有NN个人,每个人都有一个编号,编号从1开始。

由于整个国家的人实在是太多了,卿学姐每次只能对一个连续区间的编号的人普及基本法。

同时卿学姐还想知道在某个时刻某个区间还有多少人没有被普及基本法。

Input

第一行两个整数N,QN,Q,表示总共有NN个人,并且有QQ次事件。

接下来QQ行,每行三个整数t,L,Rt,L,R。如果tt是11,代表在这时,卿学姐向闭区间L,RL,R的人普及基本法。如果tt是22,代表在这时,卿学姐想知道闭区间L,RL,R里面有多少人还没有被普及基本法。

1≤N≤1000000001≤N≤100000000

1≤Q≤1000001≤Q≤100000

1≤t≤21≤t≤2

1≤L≤R≤N1≤L≤R≤N

Output

输出每个卿学姐想知道的答案

Sample input and output

Sample Input Sample Output
5 3
1 1 2
1 4 5
2 2 4
1

emmmm......做了这题之后感觉自己学到了很多有趣的东西,WA了很多次,看数据范围就知道要离散化,在一开始的时候,建树直接给节点赋值1。。。然后肯定WA。。。因为我把区间搞丢了,要离散成右闭左开的区间。。。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
const int N = + ;
int sum[N << ], col[N << ]; vector<int> v;
map<int, int> dic; struct node{
int t, l, r;
}M[N]; void PushUP(int rt){
sum[rt] = sum[rt << ] + sum[rt << |];
} void PushDown(int rt){
if(col[rt]){
col[rt << ] = col[rt << |] = ;
sum[rt << ] = sum[rt << |] = ;
col[rt] = ;
}
} void Build(int l, int r, int rt){
col[rt] = ;
if(l == r){
sum[rt] = v[l] - v[l - ];
return;
}
int m = (l + r) >> ;
Build(lson);
Build(rson);
PushUP(rt);
} void Updata(int L, int R, int l, int r, int rt){
if(L <= l && r <= R){
col[rt] = ;
sum[rt] = ;
return;
}
PushDown(rt);
int m = (l + r) >> ;
if(L <= m) Updata(L, R, lson);
if(R > m) Updata(L, R, rson);
PushUP(rt);
} int Query(int L, int R, int l, int r, int rt){
if(L <= l && r <= R){
return sum[rt];
}
PushDown(rt);
int m = (l + r) >> ;
int ret = ;
if(L <= m) ret += Query(L, R, lson);
if(R > m) ret += Query(L, R, rson);
return ret;
} void Work(int n, int m){
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int k = v.size();
for(int i = ; i < k; i++)
dic[v[i]] = i; Build(, k, );
for(int i = ; i <= m; i++){
if(M[i].t == ) Updata(dic[M[i].l], dic[M[i].r], , k, );
else printf("%d\n", Query(dic[M[i].l], dic[M[i].r], , k, ));
}
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
v.push_back();
for(int i = ; i <= m; i++){
scanf("%d %d %d", &M[i].t, &M[i].l, &M[i].r);
v.push_back(M[i].l); v.push_back(M[i].r);
v.push_back(M[i].l + );
}
Work(n, m);
}

B - 卿学姐与基本法 (离散化+成段更新+区间求和)的更多相关文章

  1. A - 卿学姐与公主(线段树+单点更新+区间极值)

    A - 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  2. cdoj1325卿学姐与基本法

    地址:http://acm.uestc.edu.cn/#/problem/show/1325 题目: 卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others)     ...

  3. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  4. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  5. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  6. POJ训练计划2777_Count Color(线段树/成段更新/区间染色)

    解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...

  7. poj 3468 线段树 成段增减 区间求和

    题意:Q是询问区间和,C是在区间内每个节点加上一个值 Sample Input 10 51 2 3 4 5 6 7 8 9 10Q 4 4Q 1 10Q 2 4C 3 6 3Q 2 4Sample O ...

  8. poj 3669 线段树成段更新+区间合并

    添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...

  9. hdu 1698 线段树(成段替换 区间求和)

    一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值 Sample Input11021 5 25 9 3 Sample OutputCase 1: The ...

随机推荐

  1. Bootstap

    Bootstrap框架 Bootstrap框架 Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序 ...

  2. AttributeError: module 'datetime' has no attribute 'now'

    在用时间转化时,一直报AttributeError: module 'datetime' has no attribute 'now', 我用的 import datetime   datetime ...

  3. Springboot入门:

    Springboot入门: 1.springboot是基于spring的全新框架,设计目的:简化spring应用配置和开发过程. 该框架遵循“约定大于配置”原则,采用特定的方式进行配置,从而事开发者无 ...

  4. nmon性能监控

    1.nmon下载地址 2../nmon_x86_rhel52 3.根据上面提示的快捷键进行输入即可显示相应的资源耗用情况,如输入:c.m.d(显示cpu.内存.磁盘使用情况) 4.输入数据到文件 ./ ...

  5. NOIP2002-字串变换【双向BFS】

    NOIP2002-字串变换 Description 已知有两个字串A,BA,B及一组字串变换的规则(至多66个规则): A_1A1​ ->B_1B1​ A_2A2​ -> B_2B2​ 规 ...

  6. HTTP访问控制(CORS)踩坑小记

    前几天在帮后端排查一个cors的问题的时候发现的一些小坑特此记录 ** cors的本质是出于安全原因,浏览器限制从脚本内发起的跨源HTTP请求. 例如,XMLHttpRequest和FetchAPI遵 ...

  7. Vue 中 双向绑定数据

    1.文本 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  8. @清晰掉 C++ 中的 enum 结构在内存中是怎么存储的?

     C++ 中的 enum 结构在内存中是怎么存储的? C++ C++ 中的 enum 结构在内存中是怎么存储的?里面存储的是常量值吗?   关于占用内存的大小,enum类型本身是不占内存的,编译器直接 ...

  9. libusb获取usb设备的idVendor(vid),idProduct(pid),以及Serial Number

    发表于2015/6/23 21:55:11  4594人阅读 最近在做关于usb设备的项目,用到了libusb,发现关于这个的函数库的介绍,讲解很少,下面仅仅是简单展示一些基本的使用方法,以备后用. ...

  10. nginx中lua动态返回文件

    原来还可以这么操作,lua动态获取内容然后返回,下面是实例,可以做到先返回一个字符串,然后过5秒再返回另外一个字符串 ngx.say("hello") ngx.flush(true ...