Albert_Tesla

2.3万

Hdw
Ac过家家
10serrrrrr
acwing_7441

CrazyQi
Mark1St

kzyz

yxc的小迷妹
ydl
Dist

#define pb push_back
class Solution {
public:
int n, m;
vector<vector<int>> tmp;

vector<vector<int>> differenceOfDistinctValues(vector<vector<int>>& grid) {
m = (int) grid.size();
n = (int) grid[0].size();
vector<vector<int>> ans;
tmp = grid;

for(int i = 0; i < m; i ++) {
vector<int> res;
for(int j = 0; j < n; j ++) {
res.pb(yuri(i, j));
}

ans.pb(res);
}

return ans;
}

int yuri(int x, int y) {
set<int> S, S1;
for(int i = 0; i <= x - 1; i ++) {
int j = i + y - x;
if(j >= 0 && j < n)
S.insert(tmp[i][j]);
}

for(int i = x + 1; i < m; i ++) {
int j = i + y - x;
if(j >= 0 && j < n)
S1.insert(tmp[i][j]);
}

return abs(int (S.size()) - int (S1.size()));
}
};


class Solution {
public:
int buyChoco(vector<int>& a, int money) {
sort(a.begin(), a.end());
int x = money - a[0] - a[1];

if(x >= 0) {
return x;
} else {
return money;
}
}
};


class Solution {
public:
string removeTrailingZeros(string num) {
int len = num.length(), index = len - 1;
for(int i = len - 1; i >= 0; i --) {
if(num[i] != '0') {
index = i;
break;
}
}

return num.substr(0, index + 1);
}
};


#define pb push_back
class Solution {
public:
bool check(string s) {
int len = s.length();
for(int i = 0; i < len - 1; i ++) {
string s1 = s.substr(i, 2);
if(s1 == "AB" || s1 == "CD") return true;
}

return false;
}

int minLength(string s) {
int len = s.length();

while(len != 0 && check(s)) {
for(int i = 0; i < len - 1; i ++) {
string s1 = s.substr(i, 2);
if(s1 == "AB" || s1 == "CD") {
s.erase(s.begin() + i, s.begin() + i + 2);
break;
}
}

len = s.length();
}

return s.length();
}
};


#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
LL a, b;

int cal(string s1, string s2) {
int len1 = s1.length(), len2 = s2.length();
int res = 0;

for(int i = len1 + 1; i <= len2 - 1; i ++)
res += (i - 1);

if(len1 != len2) {

string s3 = "", s4 = "";
for(int i = 1; i <= len1; i ++) s3 += '1';
for(int i = 1; i <= len2; i ++) s4 += '1';

for(int i = 1; i < len1; i ++) {
string tmp = s3;
tmp[i] = '0';
if(tmp >= s1) res ++;
}

for(int i = 1; i < len2; i ++) {
string tmp = s4;
tmp[i] = '0';
if(tmp <= s2) res ++;
}

} else {
string s3 = "";
for(int i = 1; i <= len1; i ++) s3 += '1';
for(int i = 1; i < len1; i ++) {
string tmp = s3;
tmp[i] = '0';
if(tmp >= s1 && tmp <= s2) res ++;
}
}

return res;
}

void yuri() {
LL x1 = a, x2 = b;
string s1 = "", s2 = "";

while(x1 != 0) {
char ch = (x1 % 2) + '0';
s1 += ch;
x1 /= 2;
}

reverse(s1.begin(), s1.end());

while(x2 != 0) {
char ch = (x2 % 2) + '0';
s2 += ch;
x2 /= 2;
}

reverse(s2.begin(), s2.end());

cout << cal(s1, s2) << '\n';
}

int main() {
cin >> a >> b;

yuri();
return 0;
}


class Solution {
public:
int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
int m, n;
unordered_map<int, int> row, col;
unordered_map<int, int> R, C;

m = (int) mat.size(), n = (int) mat[0].size();

for(int i = 0; i < m; i ++)
for(int j = 0; j < n; j ++) {
R[mat[i][j]] = i, C[mat[i][j]] = j;
}

for(int i = 0; i < arr.size(); i ++) {
int x = R[arr[i]], y = C[arr[i]];
row[x] ++, col[y] ++;
if(row[x] == n || col[y] == m) {
return i;
}
}

return -1;
}
};


class Solution {
public:
bool doesValidArrayExist(vector<int>& derived) {
int res = 0;
for(int x : derived) {
if(x == 1) res ++;
}

if(res % 2 == 0) return true;
else return false;
}
};


#define pb push_back
class Solution {
public:
vector<int> circularGameLosers(int n, int k) {
unordered_map<int, int> mp;
int cnt = 1, res = 1;
vector<int> ans;

while(1) {
mp[res] ++;
if(mp[res] == 2) break;

res = (res + k * cnt) % n;
if(res == 0) res = n;
cnt ++;
}

for(int i = 1; i <= n; i ++) {
if(! mp[i]) {
ans.pb(i);
}
}

return ans;
}
};


typedef long long LL;
const int mod = 1e9 + 7;
class Solution {
public:
int sumOfPower(vector<int>& nums) {
sort(nums.begin(), nums.end());
LL s = 0, ans = 0;

for(LL x : nums) {
ans = (ans + (x * x % mod * (x + s)) % mod ) % mod;
s = (2 * s + x) % mod;
}

return ans;
}
};