代码拉取完成,页面将自动刷新
#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]]
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。