my approach for b: to or all numbers from n-m to n+m, we just check the maximum index in bit representation of max(0,n-m) from right that is different from n+m; then just or n+m with the number with all the bits set from the right. Code: #include #include using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ int n,m; cin>>n>>m; if(n==0){ if(m==0){ cout
My approach for B:- Let L and R differ at 6th bit, then from MSB to 7th bit, every thing will be same in L and R, at 6th bit, since L < R, L will have 0 and R will have 1 at 6th bit Now, since L to R is a range, we have ......1000000 as the smallest number having MSB to 7th bit similar to L and R because every number in this range will have same MSB to 7th bit, and we have ......0111111 as the largest number having MSB to 7th bit similar to L and R, and these two will give all bit from 6th to 0th as set in OR from L to R, and remaining MSB to 7th bit are same in all the numbers, so L|R will give that Final answer is (L | R | (2^i)-1 ) where i is one more than first different bit i.e. here 6+1 = 7, as this will give ......1111111 Anyway the question is usually Div 2 C, but this time it was Div 2 B
My approach for B : we have range as n-m to n+m so for each bit from 0 to 30 I checked if it can be present in the range int res = 0; int back = 0; for(int bit = 0; bit >bit)&1){ res += (1
my approach for b:
to or all numbers from n-m to n+m, we just check the maximum index in bit representation of max(0,n-m) from right that is different from n+m; then just or n+m with the number with all the bits set from the right.
Code:
#include
#include
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
if(n==0){
if(m==0){
cout
I also did that by the same approach 😅
My approach for B:-
Let L and R differ at 6th bit, then from MSB to 7th bit, every thing will be same in L and R, at 6th bit, since L < R, L will have 0 and R will have 1 at 6th bit
Now, since L to R is a range, we have ......1000000 as the smallest number having MSB to 7th bit similar to L and R because every number in this range will have same MSB to 7th bit, and we have ......0111111 as the largest number having MSB to 7th bit similar to L and R, and these two will give all bit from 6th to 0th as set in OR from L to R, and remaining MSB to 7th bit are same in all the numbers, so L|R will give that
Final answer is (L | R | (2^i)-1 ) where i is one more than first different bit i.e. here 6+1 = 7, as this will give ......1111111
Anyway the question is usually Div 2 C, but this time it was Div 2 B
My approach for B :
we have range as n-m to n+m
so for each bit from 0 to 30 I checked if it can be present in the range
int res = 0;
int back = 0;
for(int bit = 0; bit >bit)&1){
res += (1
Bro can you please elaborate more.
In Ques B: What is y_combinator that you used in segment tree?
Its just a fancy way to write recursive function.
usaco.guide/general/lambda-funcs?lang=cpp
Bhai is B ne jo dimag kharab kra tha na mera ki kya batau. Btw love your content thank you.
How can you prove your solution will work always for C ?
Official editorial has a visual proof codeforces.com/blog/entry/129848
Didn't even solved E 🤦♂️
My skill issue tbh.
Wild comment