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;
int main()
{
long long N;
cin >> N;
long long MOD = 1000000007;
vector<long long> D(N), X(N);
for (long long i = 0; i < N; i++)
{
cin >> D[i] >> X[i];
}
vector<long long> dp(N, 0);
dp[0] = 1;
vector<vector<long long>> ST(sqrt(N) + 1);
for (long long i = 1; i <= sqrt(N); i++)
{
ST[i].assign(i, 0);
}
priority_queue<vector<long long>> PQ;
long long tot = 0;
for (long long i = 0; i < N; i++)
{
for (long long j = 1; j <= sqrt(N); j++)
{
dp[i] = (dp[i] + ST[j][i % j]) % MOD;
}
tot = (tot + dp[i]) % MOD;
if (D[i] > sqrt(N))
{
long long temp = i;
for (long long j = 0; j < X[i]; j++)
{
temp += D[i];
if (temp >= N)
break;
dp[temp] = (dp[temp] + dp[i]) % MOD;
}
}
else if (D[i] != 0)
{
ST[D[i]][i % D[i]] = (ST[D[i]][i % D[i]] + dp[i]) % MOD;
PQ.push({-(i + X[i] * D[i]), D[i], dp[i]});
}
while (!PQ.empty() && -PQ.top()[0] <= i)
{
ST[PQ.top()[1]][i % PQ.top()[1]] = (ST[PQ.top()[1]][i % PQ.top()[1]] + MOD - PQ.top()[2]) % MOD;
PQ.pop();
}
}
cout << tot;
}
# | 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... |