description
在平面內有一條長度為n的線段(不計入答案),可以對進行以下2種操作:
1、把從x到y的再加一條線段
2、查詢從x到x+1有多少條線段
input
第一行輸入n,m
第2~m+1行,每行2個數x,y,表示從x到y再加一條線段
最後一行輸入2個數,為x和x+1,查詢x到x+1的線段數目
output
輸出x到x+1的線段數目
sample input
7 22 53 6
4 5sample output
hint
【資料規模】
100%滿足1≤n≤100000,1≤x≤y≤n
線段樹或暴力
線段樹練習題一
#include
#include
#include
#include
using
namespace std;
int n,l,ans,x,y,h,t;
struct c
a[400010];
void
insert
(int dep,
int x,
int y)
//線段樹
else
if(y<=mid)
insert(2
*dep,x,y)
;else
if(x>=mid)
insert(2
*dep+
1,x,y)
;else
}voidb(
int i)
//建樹
}int
countt
(int dep,
int l,
int r)
//輸出
if(l>=mid)
}return ans;
}int
main()
scanf
("%d%d"
,&h,
&t);
printf
("%d"
,countt(1
,h,t));
}
#include
using
namespace std;
long
long n,m,x1,y1,s,x[
100005
],y[
100005];
intmain()
線段樹練習四
輸入輸出解釋 第一行兩個數n,m 表示長度為n的線段 接下來的m行讀入x,y 表示在 x,y 的區間中加入一條線段 最後一行兩個數x,y 輸出x到y這乙個區間中的線段數 保證x 1 y 樣例輸入 7 5 2 3 2 5 2 4 4 5 2 4 2 4 樣例輸出 3 做法 當某線段能夠完整覆蓋某個結點...
線段樹 SSLOJ 2647 線段樹練習四
ssl oj ssloj sslo j2647 2647 2647 在平面內有一條長度為n的線段 也算一條線段 可以對進行以下2種操作 1 x y 把從x到y的再加一條線段 2 x 查詢從x到x 1有多少條線段 第一行輸入n,m 第2 m 1行,每行3個數 對於每個查詢操作,輸出線段數目 7 2 2...
線段樹練習
一鍵挖礦 includeusing namespace std define n 2000010 define int long long define f x x 1 x 3 int n,m,tg n x n y n tx 4 ty 4 ans vectorv n struct vac n va ...