#include <bits/stdc++.h>
using namespace std;
#define ll long long
constexpr ll mod = 1e9+7;
set <int> s;
void add(int a)
{
if(a == -1) return;
if(a == 0) a++;
if(s.count(a+1)) s.erase(a+1), add(a+2);
else if(s.count(a-1)) s.erase(a-1), add(a+1);
else if(s.count(a)) s.erase(a), add(a-2), add(a+1);
else s.insert(a);
}
int main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
int n; cin >> n;
for(int i=1; i<=n; i++)
{
int a; cin >> a; add(a);
int prev=0;
ll dp[2];
dp[0] = 1, dp[1] = 0;
for(int x:s)
{
pair <ll,ll> w = {(dp[0]+dp[1])%mod,((x-prev)/2*dp[1] + (x-prev-1)/2*dp[0])%mod};
dp[0] = w.first; dp[1] = w.second;
prev=x;
}
cout << (dp[0]+dp[1])%mod << '\n';
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |