1 Star 0 Fork 0

Janu C./力扣刷题记录

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
6209.cpp 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
Janu C 提交于 2022-10-16 01:07 . 同步之前的代码
#include <bits/stdc++.h>
using namespace std;
void print(const vector<int> &);
void print(const vector<unsigned> &v);
class Solution
{
public:
vector<int> productQueries(int n, vector<vector<int>> &&queries)
{
vector<int> result;
vector<unsigned> powers;
for (int i = 0; n >= 1; i++, n /= 2)
{
if (n % 2)
powers.push_back(pow(2, i));
}
for (const vector<int> &e : queries)
{
long long val = 1;
for (int i = e[0]; i <= e[1]; i++)
{
val *= powers[i];
while (val >= 1000000007ll)
val -= 1000000007ll;
}
result.push_back((int)val);
}
return result;
}
};
void print(const vector<unsigned> &v)
{
for (const &e : v)
{
cout << e << " ";
}
cout << endl;
}
void print(const vector<int> &v)
{
for (const &e : v)
{
cout << e << " ";
}
cout << endl;
}
int main()
{
Solution s;
vector<int> v;
// v = s.productQueries(15, {{0, 1}, {2, 2}, {0, 3}});
// print(v);
v = s.productQueries(508, {{0, 6}});
// v = s.productQueries(919, {{0, 6}});
print(v);
return 0;
}
/*
[[5,5],[4,4],[0,1],[1,5],[4,6],[6,6],[5,6],[0,3],[5,5],[5,6],[1,2],[3,5],[3,6],[5,5],[4,4],[1,1],[2,4],[4,5],[4,4],[5,6],[0,4],[3,3],[0,4],[0,5],[4,4],[5,5],[4,6],[4,5],[0,4],[6,6],[6,6],[6,6],[2,2],[0,5],[1,4],[0,3],[2,4],[5,5],[6,6],[2,2],[2,3],[5,5],[0,6],[3,3],[6,6],[4,4],[0,0],[0,2],[6,6],[6,6],[3,6],[0,4],[6,6],[2,2],[4,6]]
256,128,2,4194304,16777216,512,131072,128,256,131072,8,524288,268435456,256,128,2,8192,32768,128,131072,16384,16,16384,4194304,128,256,16777216,32768,16384,512,512,512,4,4194304,16384,128,8192,256,512,4,64,256
508
[[0,4],[5,6],[5,6],[0,3],[4,6],[3,3],[1,3],[5,5],[3,3],[5,5],[0,6],[4,6],[4,4],[5,5],[4,6],[2,3],[4,6],[4,4],[2,4],[3,6],[2,6],[0,6],[5,5],[2,2],[6,6],[4,4],[4,4],[6,6],[1,2],[0,1],[6,6],[0,2],[6,6],[0,4],[6,6],[0,6],[6,6],[0,4],[0,3],[1,4],[4,5],[4,5],[6,6],[3,3],[3,6],[3,3],[2,6],[3,5],[1,6],[6,6],[6,6],[0,3],[4,5],[4,4],[4,4],[1,1],[3,6],[4,4],[0,3],[2,6],[3,5],[4,6],[6,6],[2,3],[4,6],[3,5],[5,6],[1,2],[2,2],[1,3],[5,6],[4,6],[2,5],[3,6],[1,1],[1,2],[0,6],[6,6],[1,1],[2,4],[1,2],[2,5],[3,6],[4,5],[0,3],[0,5],[1,1],[2,6],[0,3],[0,0],[5,6],[5,5],[0,4]]
919
[[5,5],[4,4],[0,1],[1,5],[4,6],[6,6],[5,6],[0,3],[5,5],[5,6],[1,2],[3,5],[3,6],[5,5],[4,4],[1,1],[2,4],[4,5],[4,4],[5,6],[0,4],[3,3],[0,4],[0,5],[4,4],[5,5],[4,6],[4,5],[0,4],[6,6],[6,6],[6,6],[2,2],[0,5],[1,4],[0,3],[2,4],[5,5],[6,6],[2,2],[2,3],[5,5],[0,6],[3,3],[6,6],[4,4],[0,0],[0,2],[6,6],[6,6],[3,6],[0,4],[6,6],[2,2],[4,6]]
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/janu-c/LeetCode.git
git@gitee.com:janu-c/LeetCode.git
janu-c
LeetCode
力扣刷题记录
master

搜索帮助