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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值

發(fā)布時(shí)間:2023/12/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Problem Description
You are given an array a1,a2,…,an(?i∈[1,n],1≤ai≤n). Initially, each element of the array is unique.

Moreover, there are m instructions.

Each instruction is in one of the following two formats:

  • (1,pos),indicating to change the value of apos to apos+10,000,000;
  • (2,r,k),indicating to ask the minimum value which is not equal to any ai ( 1≤i≤r ) and **not less ** than k.
  • Please print all results of the instructions in format 2.

    Input
    The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.

    In each test case, there are two integers n(1≤n≤100,000),m(1≤m≤100,000) in the first line, denoting the size of array a and the number of instructions.

    In the second line, there are n distinct integers a1,a2,…,an (?i∈[1,n],1≤ai≤n),denoting the array.
    For the following m lines, each line is of format (1,t1) or (2,t2,t3).
    The parameters of each instruction are generated by such way :

    For instructions in format 1 , we defined pos=t1⊕LastAns . (It is promised that 1≤pos≤n)

    For instructions in format 2 , we defined r=t2⊕LastAns,k=t3⊕LastAns. (It is promised that 1≤r≤n,1≤k≤n )

    (Note that ⊕ means the bitwise XOR operator. )

    Before the first instruction of each test case, LastAns is equal to 0 .After each instruction in format 2, LastAns will be changed to the result of that instruction.

    (∑n≤510,000,∑m≤510,000 )

    Output
    For each instruction in format 2, output the answer in one line.

    Sample Input
    3
    5 9
    4 3 1 2 5
    2 1 1
    2 2 2
    2 6 7
    2 1 3
    2 6 3
    2 0 4
    1 5
    2 3 7
    2 4 3
    10 6
    1 2 4 6 3 5 9 10 7 8
    2 7 2
    1 2
    2 0 5
    2 11 10
    1 3
    2 3 2
    10 10
    9 7 5 3 4 10 6 2 1 8
    1 10
    2 8 9
    1 12
    2 15 15
    1 12
    2 1 3
    1 9
    1 12
    2 2 2
    1 9

    Sample Output
    1
    5
    2
    2
    5
    6
    1
    6
    7
    3
    11
    10
    11
    4
    8
    11

    Hint

    note:
    After the generation procedure ,the instructions of the first test case are :
    2 1 1, in format 2 and r=1 , k=1
    2 3 3, in format 2 and r=3 , k=3
    2 3 2, in format 2 and r=3 , k=2
    2 3 1, in format 2 and r=3 , k=1
    2 4 1, in format 2 and r=4 , k=1
    2 5 1, in format 2 and r=5 , k=1
    1 3 , in format 1 and pos=3
    2 5 1, in format 2 and r=5 , k=1
    2 5 2, in format 2 and r=5 , k=2

    the instructions of the second test case are :
    2 7 2, in format 2 and r=7 , k=2
    1 5 , in format 1 and pos=5
    2 7 2, in format 2 and r=7 , k=2
    2 8 9, in format 2 and r=8 , k=9
    1 8 , in format 1 and pos=8
    2 8 9, in format 2 and r=8 , k=9

    the instructions of the third test case are :
    1 10 , in format 1 and pos=10
    2 8 9 , in format 2 and r=8 , k=9
    1 7 , in format 1 and pos=7
    2 4 4 , in format 2 and r=4 , k=4
    1 8 , in format 1 and pos=8
    2 5 7 , in format 2 and r=5 , k=7
    1 1 , in format 1 and pos=1
    1 4 , in format 1 and pos=4
    2 10 10, in format 2 and r=10 , k=10
    1 2 , in format 1 and pos=2
    昨天卡了很久的一個(gè)題,你開始線段樹+set一直超時(shí),后來(lái)改了主席樹,但是還是卡了很久。。
    題意:要找出一個(gè)數(shù),這個(gè)數(shù)在1~r中不能出現(xiàn)過(guò),并且還要不小于k。并且讀入的數(shù)據(jù)還都要異或上上一次的答案。
    一開始理解錯(cuò)了,以為必須是數(shù)組里的數(shù)才行。但是第一個(gè)樣例中就有一個(gè)數(shù)不是數(shù)組里的數(shù),除此之外,題目中有說(shuō)所有的數(shù)都是獨(dú)一無(wú)二的。在執(zhí)行操作1的時(shí)候,一個(gè)數(shù)加上1e7之后,就相當(dāng)于作廢了。因?yàn)閿?shù)組中所有的數(shù)字都是不大于1e5的,所以異或之后的值也是不大于1e5的。這樣的話,在加上1e7之后,就相當(dāng)于這個(gè)值在1~r中刪除了,又可以再用了。那這樣我們把這樣的值存到一個(gè)set里面,r+1到n的值用主席樹去求。主席樹是好多權(quán)值線段樹的集合,是按著權(quán)值來(lái)的,存的是每個(gè)數(shù)的出現(xiàn)的個(gè)數(shù)。用主席樹去求r+1 ~ n中大于等于k最小的數(shù)。
    代碼如下:

    #include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std;const int maxx=1e5+100; struct node{int l;int r;int sum; }p[maxx<<5]; int a[maxx]; int root[maxx]; int n,m,tot;inline void pushup(int cur) {p[cur].sum=p[p[cur].l].sum+p[p[cur].r].sum; } inline int build(int l,int r) {int cur=++tot;p[cur].sum=0;if(l==r) return cur;int mid=l+r>>1;build(l,mid);build(mid+1,r);return cur; } inline int update(int rot,int l,int r,int pos) {int cur=++tot;p[cur]=p[rot];if(l==r) {p[cur].sum++;return cur;}int mid=l+r>>1;if(pos<=mid) p[cur].l=update(p[rot].l,l,mid,pos);else p[cur].r=update(p[rot].r,mid+1,r,pos);pushup(cur);return cur; } inline int query(int lrot,int rrot,int l,int r,int k) {if(l==r) //到達(dá)葉子節(jié)點(diǎn)后{if(p[rrot].sum-p[lrot].sum>0) return l;//如果這個(gè)值出現(xiàn)過(guò)就返回這個(gè)值,沒(méi)有就返回?zé)o窮大else return inf;}int mid=l+r>>1;if(k<=mid){int ans=inf;if(k<=l)//這里相當(dāng)于一個(gè)剪枝,在小于l的時(shí)候,如果左子樹有符合條件的就進(jìn)入左子樹,否則再進(jìn)入右子樹。{if(p[p[rrot].l].sum-p[p[lrot].l].sum>0) ans=min(ans,query(p[lrot].l,p[rrot].l,l,mid,k));else if(p[p[rrot].r].sum-p[p[lrot].r].sum>0) ans=min(ans,query(p[lrot].r,p[rrot].r,mid+1,r,k));return ans;}if(p[p[rrot].l].sum-p[p[lrot].l].sum>0) //k在l到mid之間的時(shí)候,左右子樹都有可能涉及,就左右都看一遍尋找最優(yōu)解ans=min(ans,query(p[lrot].l,p[rrot].l,l,mid,k));if(p[p[rrot].r].sum-p[p[lrot].r].sum>0) ans=min(ans,query(p[lrot].r,p[rrot].r,mid+1,r,k));return ans;}else{int ans=inf;//k大于mid的時(shí)候,直接進(jìn)入右子樹,左子樹不用找了if(p[p[rrot].r].sum-p[p[lrot].r].sum>0) ans=min(ans,query(p[lrot].r,p[rrot].r,mid+1,r,k));return ans;} }int main() {int t,t1,t2,t3,op;scanf("%d",&t);ll lastans=0;while(t--){scanf("%d%d",&n,&m);set<ll> s;s.insert(n+1);//一開始先把n+1放入集合,如果數(shù)組中的值沒(méi)有符合的就輸出n+1lastans=0;tot=0;for(int i=1;i<=n;i++) scanf("%d",&a[i]);root[0]=build(1,100001);for(int i=1;i<=n;i++) root[i]=update(root[i-1],1,100001,a[i]);while(m--){scanf("%d",&op);if(op==1){scanf("%d",&t1);t1^=lastans;s.insert(a[t1]);//把修改之后的值放入集合里}else if(op==2){scanf("%d%d",&t2,&t3);t2^=lastans,t3^=lastans;int ans=inf;if(t2!=n) ans=query(root[t2],root[n],1,100001,t3);int ans1=*s.lower_bound(t3);lastans=min(ans1,ans);printf("%d\n",lastans);}}}return 0; }

    昨天寫的超時(shí)的代碼(線段樹+set)當(dāng)個(gè)借鑒吧
    代碼如下:

    #include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std;const int maxx=1e5+100; struct node{int l;int r;set<int> s; }p[maxx<<2]; int a[maxx]; int n,m;inline int read() //輸入外掛 {int res=0,ch,flag=0;if((ch=getchar())=='-')flag=1;else if(ch>='0'&&ch<='9')res=ch-'0';while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';return flag?-res:res; } inline void Out(int a) //輸出外掛 {if(a>9)Out(a/10);putchar(a%10+'0'); } inline void pushup(int cur) {set_union(p[cur<<1].s.begin(),p[cur<<1].s.end(),p[cur<<1|1].s.begin(),p[cur<<1|1].s.end(),inserter(p[cur].s,p[cur].s.begin())); } inline void build(int l,int r,int cur) {p[cur].l=l;p[cur].r=r;p[cur].s.clear();if(l==r) {p[cur].s.insert(a[l]);return ;}int mid=l+r>>1;build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);pushup(cur); } inline set<int> query(int l,int r,int cur) {int L=p[cur].l;int R=p[cur].r;if(l<=L&&R<=r) return p[cur].s;int mid=L+R>>1;if(r<=mid) return query(l,r,cur<<1);else if(l>mid) return query(l,r,cur<<1|1);else{set<int> a=query(l,mid,cur<<1);set<int> b=query(mid+1,r,cur<<1|1);set<int> x;set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(x,x.begin()));return x;} } int main() {int t,t1,t2,t3,op;t=read();while(t--){int lastans=0;n=read(),m=read();for(int i=1;i<=n;i++) a[i]=read();build(1,n,1);set<int> s;s.insert(n+1);while(m--){op=read();if(op==1){t1=read();t1^=lastans;s.insert(a[t1]);}else{t2=read(),t3=read();t2^=lastans;t3^=lastans;int ans1=inf;if(t2!=n) {set<int> s1;s1=query(t2+1,n,1);s1.insert(n+1);ans1=*s1.lower_bound(t3);}int ans2=*s.lower_bound(t3);lastans=min(ans1,ans2);Out(lastans);}}} }

    努力加油a啊,(o)/~

    總結(jié)

    以上是生活随笔為你收集整理的array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 在厨房拨开内裤进入毛片 | 亚洲码欧美码一区二区三区 | 亚洲精品xxx | 草久久久久| 久久麻豆精品 | 亚洲va欧美va天堂v国产综合 | 俄罗斯黄色录像 | 欧美日韩一区二区三区四区 | 五月色婷 | 久操av| 国内久久久 | 成人aaaaa| 禁片天堂| 国产精品无码久久久久成人app | 国产午夜麻豆影院在线观看 | 日日碰狠狠添天天爽无码 | 日本成人一二三区 | 日韩欧美啪啪 | 超碰97免费在线 | 日本黄色一区二区 | 亚洲蜜桃精久久久久久久久久久久 | jizz性欧美15 | 国产愉拍 | 精品视频一二区 | 亚洲第四页 | 一区二区三区久久 | 91www | 午夜老司机福利 | 激情五月激情综合 | 色欲人妻综合网 | 国产喷白浆一区二区三区 | 午夜精品久久久久久久99热黄桃 | 精品午夜一区二区 | 肉色丝袜小早川怜子av | 欧美精品综合 | 精品亚洲一区二区 | a视频免费| 在线三级av| 国产午夜福利精品 | 国产精品久久久久久久久久直播 | 美女搞黄视频网站 | 国产网红在线 | 亚洲国产精品自拍视频 | 中文字幕国产日韩 | 国产成人精品视频ⅴa片软件竹菊 | 国产字幕在线观看 | 99视频免费看 | 蜜臀av88| 婷婷射丁香 | 欧美综合精品 | 日本大尺度做爰呻吟舌吻 | 精品久久久久久久久久久久久久久久 | 黄色免费一级视频 | 少妇毛片一区二区三区 | 国产情侣一区 | 精品一区二区三区四区视频 | aa一级黄色片 | 91学生片黄 | 色综合天天综合网天天看片 | 三上悠亚在线一区二区 | 欧美777| 成人综合一区二区 | 中文字幕一区二区三区四区欧美 | 嫩草国产在线 | 色综合99久久久无码国产精品 | 欧美三级自拍 | 久久久穴| 日韩亚洲国产欧美 | 性高潮网站 | 免费日韩成人 | 国产免费一区 | 影音先锋黄色资源 | 日批视频免费看 | 狠狠干干干 | 国产精品毛片一区二区三区 | 欧美激情在线免费 | 欧美三级一区 | 丰满少妇高潮久久三区 | 一区二区视频 | 亚洲69视频 | 国产色黄 | 日韩性大片 | 亚洲另类网站 | 人成在线观看 | 国产精品乱码一区二区 | 日韩一级视频在线观看 | 91亚洲精| 日本手机看片 | 污污视频在线观看免费 | 色婷五月| 一级欧美一级日韩 | 天天撸天天操 | аⅴ资源新版在线天堂 | 亚洲免费色视频 | 就去干成人网 | 99精品乱码国产在线观看 | 人人澡人人看 | 99久久国| 日韩电影在线一区 |