Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset

题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy‘s Multiset

题意:

给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值

题解:

trie树xjb搞就行,每次要贪心,尽量满足高位为1.

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;i++)
 3 using namespace std;
 4
 5 namespace trie
 6 {
 7     const int N=(2e5+7)*32;
 8     int tr[N][2],ed=-1,cnt[N];
 9     void nw(){cnt[++ed]=0,tr[ed][0]=tr[ed][1]=0;}
10     void update(int x,int c,int now=0)
11     {
12         for(int i=30;i>=0;i--)
13         {
14             int v=x>>i&1;
15             if(!tr[now][v])nw(),tr[now][v]=ed;
16             now=tr[now][v];
17             cnt[now]+=c;
18         }
19     }
20     int ask(int x,int now=0,int ans=0)
21     {
22         for(int i=30;i>=0;i--)
23         {
24             int v=x>>i&1;
25             if(!cnt[tr[now][v^1]])now=tr[now][v];
26             else now=tr[now][v^1],ans|=1<<i;
27         }
28         return ans;
29     }
30 }
31 using namespace trie;
32 int main()
33 {
34     int n,x;char op[2];
35     scanf("%d",&n);
36     nw(),update(0,1);
37     F(i,1,n)
38     {
39         scanf("%s%d",op,&x);
40         if(op[0]==‘+‘)update(x,1);
41         else if(op[0]==‘-‘)update(x,-1);
42         else printf("%d\n",ask(x));
43     }
44     return 0;
45 }

Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset

时间: 2024-08-25 09:04:03

Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset的相关文章

Codeforces Round #367 (Div. 2) ABCD

A. Beru-taxi 题解: 水,求下距离就行了 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #

Codeforces Round #367 (Div. 2) 套题

吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string>

Codeforces Round #367 (Div. 2)

A. Beru-taxi (Codeforces 706A) 水题,求一下到每个点的距离,取最小值即可 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define N using namespace std; int n,x,y,p,q,s; double t,ans=1000000000; int main() { scanf("%d%d%d&

Codeforces Round #367 Div. 2 [11110]

#include <iostream> #include <map> #include <math.h> using namespace std; int main() { double a, b; cin >> a >> b; int n; cin >> n; double MIN = 1e10; while (n--) { double x, y, v; cin >> x >> y >> v;

Codeforces Round #367 (Div. 2) 题解

A code: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #define maxn 1005 using namespace std; int main() { double ans,tans; double x0,y0,x,y,v; cin >> x0 >> y0; ans

trie树 Codeforces Round #367 D Vasiliy&#39;s Multiset

1 // trie树 Codeforces Round #367 D Vasiliy's Multiset 2 // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 3 // 思路:思路很好想,建立trie树,再贪心当前位是1则选0,0则选1 4 5 6 #include <bits/stdc++.h> 7 using namespace std; 8 #define LL long long 9 const double inf = 123456789

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿