日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ-522 Interval

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ-522 Interval 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Interval

時間限制:2000?ms ?|? 內存限制:65535?KB 難度:4 描述
There are n(1 <= n <= 100000) intervals [ai, bi] and m(1 <= m <= 100000) queries, -100000 <= ai <= bi <= 100000 are integers. Each query contains an integer xi(-100000 <= x <= 100000). For each query, you should answer how many intervals convers xi.
輸入
The first line of input is the number of test case.
For each test case,
two integers n m on the first line,?
then n lines, each line contains two integers ai, bi;
then m lines, each line contains an integer xi.
輸出
m lines, each line an integer, the number of intervals that covers xi.
樣例輸入2 3 4 1 3 1 2 2 3 0 1 2 3 1 3 0 0 -1 0 1 樣例輸出0 2 3 2 0 1 0 ? ? ? 很久沒寫樹狀數組了,正好看到了,就復習一下,本題是樹狀數組-----插線問點的問題

注意寫樹狀數組時候把區間都擴大到大于0的區間上,不能等于0.否則會一直超時,代碼如下:

?

1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 5 using namespace std; 6 7 int num[200005]; 8 9 int lowbit(int i) 10 { 11 return i & (-i); 12 } 13 14 void update(int i, int add) 15 { 16 while(i <= 200001) 17 { 18 num[i] += add; 19 i += lowbit(i); 20 } 21 } 22 23 int getsum(int x) 24 { 25 int ans = 0; 26 while(x > 0) 27 { 28 ans += num[x]; 29 x -= lowbit(x); 30 } 31 return ans; 32 } 33 34 int main() 35 { 36 int T, m, n, s, t, x; 37 scanf("%d", &T); 38 while(T--) 39 { 40 memset(num, 0, sizeof(num)); 41 scanf("%d%d", &m, &n); 42 while(m--) 43 { 44 scanf("%d%d", &s, &t); 45 update(s+100001, 1); 46 update(t+100001+1, -1); 47 } 48 while(n--) 49 { 50 scanf("%d", &x); 51 printf("%d\n", getsum(x+100001)); 52 } 53 } 54 return 0; 55 }

?

?

?

?

?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的NYOJ-522 Interval的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。