Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 3025. Find the Number of Ways to Place People I 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
long long minOperations(vector<vector<int>>& queries) {
long long ans = 0;
for (auto &q : queries) {
int l = q[0], r = q[1];
long long S = 0;
int dMax = 0;

for (int k = 1; k <= 31; k++) {
long long low = 1LL << (k - 1);
long long high = (1LL << k) - 1;
if (low > r) break;
long long a = max((long long)l, low);
long long b = min((long long)r, high);
if (a > b) continue;
long long cnt = b - a + 1;
int stepsForK = (k + 1) / 2;
S += cnt * stepsForK;
dMax = max(dMax, stepsForK);
}

long long ops = max((long long)dMax, (S + 1) / 2);
ans += ops;
}
return ans;
}
};
Loading