# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111458 | gelastropod | Trains (BOI24_trains) | C++14 | 44 ms | 5308 KiB |
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;
}
signed main()
{
int N, a, b;
cin >> N;
tree = vector<int>(N + 1, 0);
vector<pair<int, int>> vals;
for (int i = 0; i < N; i++)
{
cin >> a >> b;
vals.push_back({a, b});
}
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)
# | 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... |