Skip to content

Commit 6bd4f9d

Browse files
authored
Create 3025. Find the Number of Ways to Place People I 2 (#878)
2 parents 90b050c + 9ddc141 commit 6bd4f9d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
long long minOperations(vector<vector<int>>& queries) {
4+
long long ans = 0;
5+
for (auto &q : queries) {
6+
int l = q[0], r = q[1];
7+
long long S = 0;
8+
int dMax = 0;
9+
10+
for (int k = 1; k <= 31; k++) {
11+
long long low = 1LL << (k - 1);
12+
long long high = (1LL << k) - 1;
13+
if (low > r) break;
14+
long long a = max((long long)l, low);
15+
long long b = min((long long)r, high);
16+
if (a > b) continue;
17+
long long cnt = b - a + 1;
18+
int stepsForK = (k + 1) / 2;
19+
S += cnt * stepsForK;
20+
dMax = max(dMax, stepsForK);
21+
}
22+
23+
long long ops = max((long long)dMax, (S + 1) / 2);
24+
ans += ops;
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)