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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【bzoj2223】[Coci 2009]PATULJCI 主席树

發布時間:2025/3/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【bzoj2223】[Coci 2009]PATULJCI 主席树 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

樣例輸入

10 3

1 2?1 2?1 2?3 2?3 3

8

1?2

1 3

1 4

1 5

2?5

2 6

6 9

7 10

樣例輸出

no

yes 1

no

yes 1

no

yes 2

no

yes 3


題目大意

第一行輸入n和lim,為序列數的個數和數的范圍(1≤a[i]≤lim)

第二行輸入n個數。

第三行輸入m,為詢問個數。

以下m行輸入詢問,如題。

對于每個詢問,如果存在,輸出yes和這個數,否則輸出no。

題解

bzoj格式錯了。。。

主席樹。

對于每個詢問,判斷它能在左邊出現還是能在右邊出現,都不能則不存在,能則繼續尋找。略水。

不需要離散化。

#include <cstdio> #define N 300001 int root[N] , lp[N << 5] , rp[N << 5] , si[N << 5] , tot; void pushup(int x) {si[x] = si[lp[x]] + si[rp[x]]; } void ins(int x , int &y , int l , int r , int p) {y = ++tot;if(l == r){si[y] = si[x] + 1;return;}int mid = (l + r) >> 1;if(p <= mid) rp[y] = rp[x] , ins(lp[x] , lp[y] , l , mid , p);else lp[y] = lp[x] , ins(rp[x] , rp[y] , mid + 1 , r , p);pushup(y); } int query(int x , int y , int l , int r , int p) {if(l == r) return l;int mid = (l + r) >> 1;if(si[lp[y]] - si[lp[x]] > p) return query(lp[x] , lp[y] , l , mid , p);if(si[rp[y]] - si[rp[x]] > p) return query(rp[x] , rp[y] , mid + 1 , r , p);return 0; } int main() {int n , lim , m , i , x , y , t;scanf("%d%d" , &n , &lim);for(i = 1 ; i <= n ; i ++ ){scanf("%d" , &x);ins(root[i - 1] , root[i] , 1 , lim , x);}scanf("%d" , &m);while(m -- ){scanf("%d%d" , &x , &y);t = query(root[x - 1] , root[y] , 1 , lim , (y - x + 1) >> 1);if(t) printf("yes %d\n" , t);else printf("no\n");}return 0; }

轉載于:https://www.cnblogs.com/GXZlegend/p/6292609.html

總結

以上是生活随笔為你收集整理的【bzoj2223】[Coci 2009]PATULJCI 主席树的全部內容,希望文章能夠幫你解決所遇到的問題。

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