This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> tree;
void upd(int n, int x)
{
while (n < tree.size())
{
tree[n] += x;
tree[n] %= 1000000007;
n += n & (-n);
}
}
int qry(int a)
{
if (a == 0)
return 0;
if (a >= tree.size())
return qry(tree.size() - 1);
int ans = 0;
while (a > 0)
{
ans += tree[a];
ans %= 1000000007;
a -= a & (-a);
}
return ans;
}
vector<pair<int, int>> vals;
vector<int> dp;
int ways(int n)
{
if (dp[n] != -1) return dp[n];
if (vals[n].first == 0 || n + vals[n].first >= (int)dp.size()) return dp[n] = 1;
int ans = 1;
for (int i = n + vals[n].first, t = 0; i < (int)dp.size() && t < vals[n].second; i += vals[n].first, t++)
{
ans += ways(i);
ans %= 1000000007;
}
return dp[n] = ans;
}
signed main()
{
int N, a, b;
cin >> N;
tree = vector<int>(N + 1, 0);
dp = vector<int>(N, -1);
bool huh = false;
for (int i = 0; i < N; i++)
{
cin >> a >> b;
vals.push_back({a, b});
if (a != 1)
huh = true;
}
if (huh)
{
cout << ways(0) << '\n';
}
else
{
for (int i = N - 1; i >= 0; i--)
{
if (i + 1 >= N)
upd(i + 1, 1);
else
upd(i + 1, (1 + qry(i + 1 + vals[i].second) - qry(i)) % 1000000007);
}
cout << qry(1) << '\n';
}
}
Compilation message (stderr)
Main.cpp: In function 'void upd(long long int, long long int)':
Main.cpp:9:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | while (n < tree.size())
| ~~^~~~~~~~~~~~~
Main.cpp: In function 'long long int qry(long long int)':
Main.cpp:21:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (a >= tree.size())
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |