2021牛客多校训练7 I xay loves or

Posted 布图

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021牛客多校训练7 I xay loves or相关的知识,希望对你有一定的参考价值。

题目

链接:https://ac.nowcoder.com/acm/contest/11258/I
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

xay loves or. He gives you x and s, you need to calculate how many positive integer y satisfy xor⁡y=sx \\operatorname{or} y=sxory=s .

输入描述:

The first line contains two positive integers x and s .

It's guaranteed that 1≤x,s<2311\\le x,s<2^{31}1≤x,s<231 .

输出描述:

Print the number of y satisfy xor⁡y=sx \\operatorname{or} y=sxory=s .

示例1

输入

[复制](javascript:void(0)😉

2 5

输出

[复制](javascript:void(0)😉

0

解释与代码

给出x和s​,问存在多少个y使得x|y=s

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <limits.h>
#include <assert.h>
#include <functional>
#include <numeric>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb          push_back
#define ppb         pop_back
#define lbnd        lower_bound
#define ubnd        upper_bound
#define endl        '\\n'
#define mll         map<ll,ll>
#define msl         map<string,ll>
#define mls         map<ll, string>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define vll         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define DEBUG       cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x)  trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ini(a)      memset(a,0,sizeof(a))
#define ini2(a,b)   memset(a,b,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define case        ll T;cin>>T;for(ll Q=1;Q<=T;Q++)
#define lowbit(x)   x&(-x)
#define pr          printf
#define sc          scanf
#define _           0
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DBG(x) \\
    (void)(cout << "L" << __LINE__ \\
    << ": " << #x << " = " << (x) << '\\n')
#define TIE \\
    cin.tie(0);cout.tie(0);\\
    ios::sync_with_stdio(false);
//#define long long int

//using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF   = 0x3f3f3f3f;
const ll  LLINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e7*2+10;
const ll N = 5;

typedef struct LNode{
    int coef,index;
    struct LNode *next;
}LNode,*LinkList;

struct SegmentTree{
	int l, r;
	int dat;
}t[N*4];

bool cmp(int a,int b){
	return a>b;
}


void solve(){
	ll x, s, ans = 1, xx, ss;
	cin>>x>>s;
	xx = x,ss = s;
	ll a, b, cnt = 0;
	if (x>s) {
		cout<<0<<endl;
		return ;
	} else if (x<s) {
		for (; x; x>>=1,s>>=1) {
			if ((x&1) && (s&1)==0) {
				cout<<0<<endl;
				return ;
			} else if ((x&1) && (s&1)) {
				ans*=2;
			} else if ((x&1)==0 && (s&1)) {
				cnt = 1;
			}
		}
//		if (cnt) {
//			cout<<ans<<endl;
//		} else {
//			cout<<ans-1<<endl;
//		}
	} else {
		for (; x; x>>=1) {
			if (x&1) {
				ans*=2;
			}
		}
//		cout<<ans-1<<endl;//去除0 
	}
	if ((0|xx)==ss) {
		ans--;
	}
	cout<<ans<<endl;
}

int main()
{
//	TIE;
//    #ifndef ONLINE_JUDGE
//    freopen ("input.txt","r",stdin);
//    #else
//    #endif
	solve();
//    case{solve();}
//    case{cout<<"Case "<<Q<<":"<<endl;solve();}
//	return ~~(0^_^0);
}



以上是关于2021牛客多校训练7 I xay loves or的主要内容,如果未能解决你的问题,请参考以下文章

牛客多校7.H.xay loves count 思维

2021牛客多校7 - xay loves trees(dfs序+主席树-标记永久化)

牛客多校2021 F.xay loves trees(树状数组+树上的滑动窗口)

牛客多校7.F.xay loves trees 主席树+dfs序

牛客多校训练赛补题

牛客多校训练赛补题