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 N;
const int MAX = 1e5, MOD = 1e9 + 7;
vector<int> fenwick(MAX + 5);
void update(int n, int v) {
for (; n <= N; n += n & -n) {
fenwick[n] = (fenwick[n] + v) % MOD;
}
}
int query(int n) {
int S = 0;
for (; n > 0; n -= n & -n) {
S = (S + fenwick[n]) % MOD;
}
return S;
}
int main() {
cin >> N;
int D, X, S = 0;
update(1, 1);
for (int i = 1; i <= N; i++) {
cin >> D >> X;
const int Q = query(i);
update(i + 1, Q);
update(i + X + 1, -Q);
}
for (int i = 0; i < N; i++) {
S = (S + query(i)) % MOD;
}
cout << (S + MOD) % MOD;
}
# | 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... |