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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【CodeForces - 706D】Vasiliy's Multiset(01字典树)

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 706D】Vasiliy's Multiset(01字典树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Author has gone out of the stories about Vasiliy, so here is just a formal task description.

You are given?q?queries and a multiset?A, initially containing only integer?0. There are three types of queries:

  • "+ x"?— add integer?x?to multiset?A.
  • "- x"?— erase one occurrence of integer?x?from multiset?A. It's guaranteed that at least one?x?is present in the multiset?A?before this query.
  • "? x"?— you are given integer?x?and need to compute the value?, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer?x?and some integer?y?from the multiset?A.
  • Multiset is a set, where equal elements are allowed.

    Input

    The first line of the input contains a single integer?q?(1?≤?q?≤?200?000)?— the number of queries Vasiliy has to perform.

    Each of the following?q?lines of the input contains one of three characters '+', '-' or '?' and an integer?xi?(1?≤?xi?≤?109). It's guaranteed that there is at least one query of the third type.

    Note, that the integer?0?will always be present in the set?A.

    Output

    For each query of the type '?' print one integer?— the maximum value of bitwise exclusive OR (XOR) of integer?xi?and some integer from the multiset?A.

    Example

    Input

    10 + 8 + 9 + 11 + 6 + 1 ? 3 - 8 ? 3 ? 8 ? 11

    Output

    11 10 14 13

    Note

    After first five operations multiset?A?contains integers?0,?8,?9,?11,?6?and?1.

    The answer for the sixth query is integer??— maximum among integers?,?,?,??and?.

    題目大意:

    維護一個初始時只有元素0的多重集,有三種操作

    1? x: 添加一個數x

    2? x: 刪除一個數x

    3? x: 詢問一個數x與這個集合中的某一個元素的異或值最大是多少。

    總共q次操作,每次操作是xi? (1?≤?xi?≤?1e9,1?≤?q?≤?200?000)

    解題報告:

    直接01字典樹,注意剛開始需要先插入0.再就是數組需要開大一些左右,2e5是不夠的。

    AC代碼:

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 1e7 + 5; int tr[MAX][2],tot,num[MAX]; void ins(int x) {int rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;if(tr[rt][tar] == 0) tr[rt][tar] = ++tot;rt=tr[rt][tar]; num[rt]++;} } void del(int x) {int rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;rt=tr[rt][tar]; num[rt]--;} } int cal(int x) {int res = 0,rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;if(num[tr[rt][!tar]] > 0) res |= (1<<bit),rt=tr[rt][!tar];else rt = tr[rt][tar];if(rt == 0) break;} return res; } int main() {int q,x; char op[5];cin>>q;ins(0);while(q--) {scanf("%s%d",op,&x);if(op[0] == '+') ins(x);if(op[0] == '-') del(x);if(op[0] == '?') printf("%d\n",cal(x));}return 0 ; }

    ?

    總結

    以上是生活随笔為你收集整理的【CodeForces - 706D】Vasiliy's Multiset(01字典树)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 成人午夜精品 | 欧美综合自拍亚洲综合图片区 | 婷婷在线免费 | 吊视频一区二区三区 | 亚洲欧美日韩另类在线 | 日韩国产毛片 | 在线观看免费高清在线观看 | 禁断介护av一区二区 | 久久久久中文 | 青草视频在线观看视频 | 超碰综合在线 | 日韩乱淫| 中文字幕网伦射乱中文 | 亚州春色 | 日韩av在线网| 青草综合 | 麻豆久久久午夜一区二区 | 精产国品一区二区 | 国产日韩欧美中文 | 一区二区三区四区亚洲 | 日本欧美一本 | 狠狠鲁影院 | 国产男同gay网站 | 欧美九九九 | 国产亚洲精品久久久久久青梅 | 黄p在线播放 | 伊人久久一区 | 视频污在线观看 | 麻豆传媒网站在线观看 | 国产精品色呦呦 | 成年人福利网站 | 麻豆成人久久精品一区二区三区 | 日韩欧美在线播放 | 亚洲人成无码www久久久 | 日韩精品一区二区在线看 | 久久精品在线 | 中文字幕免费高清在线观看 | av在线男人天堂 | av美国| 青青毛片| 亚洲成人一级片 | 污污网站在线免费观看 | a视频在线 | 校园春色综合网 | xxxxxx欧美| 一级日韩一级欧美 | 午夜影院0606 | 福利在线一区二区 | 日韩精品福利在线 | 欧美高清一区二区 | 亚洲 欧美 日韩 在线 | 欧美少妇毛茸茸 | 国产夫妻av | 亚洲av网址在线 | 久草视频精品在线 | 总裁边开会边做小娇妻h | 视频二区在线 | 国产男女猛烈无遮挡免费视频 | 成人精品一区二区三区中文字幕 | 欧美一级黄色片 | 日韩一级片一区二区 | 亚洲成人av在线播放 | 国模视频在线 | 亚洲乱码国产乱码精品天美传媒 | 日韩不卡视频在线观看 | 日韩亚洲欧美在线观看 | 午夜性激情 | 欧美色88 | 色欲AV无码精品一区二区久久 | 亚洲国产精品999 | 一区二区在线精品 | 日韩在线播放中文字幕 | 男男play视频 | 一区二区免费在线观看视频 | 国产精品乱码一区二区三区 | 亚洲伦理网 | 日本久久精品视频 | 人妻视频一区二区 | 中文字幕一区二区三区免费 | 91中文字幕在线播放 | 欧美成人看片黄a免费看 | a免费在线观看 | 99色婷婷 | 国产小视频在线观看 | 欧美黄色性生活 | 国产视频黄 | 拔插拔插海外华人永久免费 | 青青毛片 | 国产精品久久国产精麻豆96堂 | 欧美黑人一区二区三区 | 99re国产精品 | 不卡av免费在线观看 | 内射一区二区三区 | 亚洲a在线观看 | 色婷婷在线影院 | 97人人爽人人爽人人爽人人爽 | 国产乱一区二区三区 | 一曲二曲三曲在线观看中文字幕动漫 | 国产69精品久久久久久 |