#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
#define matrix vector<vector<int>>
matrix operator * (matrix a,matrix b){
matrix ans(2,vector<int>(2,0));
for(int i=0;i<2;++i)
for(int j=0;j<2;++j)
for(int k=0;k<2;++k)
ans[i][j]=add(ans[i][j],mul(a[i][k],b[k][j]));
return ans;
}
matrix build(int sz){
return {{1,1},{(sz-1)/2,sz/2}};
}
const int N=100050;
const int M=30*N*2;
const int lim=1e9+1000;
int ls[M],rs[M],tsz,root;
matrix idx,seg[M];
void Set(int&c,int ss,int se,int qi,matrix m){
if(!c)c=++tsz,seg[c]=idx;
if(ss==se){seg[c]=m;return;}
int mid=ss+se>>1;
if(qi<=mid)Set(ls[c],ss,mid,qi,m);
else Set(rs[c],mid+1,se,qi,m);
seg[c]=seg[rs[c]]*seg[ls[c]];
}
set<int> f;
void Add(int a){
f.insert(a);
auto it=f.find(a);
Set(root,1,lim,a,build(a-*prev(it)));
if(next(it)!=f.end()){
Set(root,1,lim,*next(it),build(*next(it)-a));
}
}
void Del(int a){
auto it=f.find(a);
Set(root,1,lim,a,idx);
if(next(it)!=f.end()){
Set(root,1,lim,*next(it),build(*next(it)-*prev(it)));
}
f.erase(it);
}
map<int,int> cnt;
void Inc(int a){
cnt[a]++;
if(cnt[a]==1)Add(a);
}
void Dec(int a){
cnt[a]--;
if(cnt[a]==0)Del(a);
}
void Fix(int a){
if(cnt[a]&&cnt[a-1]){
Dec(a);
Dec(a-1);
Inc(a+1);
Fix(a+1);
Fix(a+2);
}else if(cnt[a]==2){
if(a==1){
Dec(a);Dec(a);
Inc(a+1);
Fix(a+1);
Fix(a+2);
}else{
Inc(max(a-2,1));
Dec(a);Dec(a);
Inc(a+1);
Fix(max(a-2,1));
Fix(max(a-2,1)+1);
Fix(a+1);
Fix(a+2);
}
}
}
int Solve(){
matrix m=seg[root];
return add(m[0][0],m[1][0]);
/*int dp[2]={1,0},las=0;
for(auto it:cnt){
int i=it.first;
if(!cnt[i])continue;
int d0=add(dp[0],dp[1]);
int sz=i-las-1;
int d1=add(mul(dp[0],sz/2),mul(dp[1],(sz+1)/2));
las=i;dp[0]=d0;dp[1]=d1;
}
return add(dp[0],dp[1]);*/
}
int main(){
f.insert(0);
idx={{1,0},{0,1}};
seg[0]=idx;
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++){
int a;
scanf("%i",&a);
Inc(a);
Fix(a);
Fix(a+1);
printf("%i\n",Solve());
}
return 0;
}
Compilation message
fib.cpp: In function 'void Set(int&, int, int, int, std::vector<std::vector<int> >)':
fib.cpp:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int mid=ss+se>>1;
| ~~^~~
fib.cpp: In function 'int main()':
fib.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
101 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
fib.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
104 | scanf("%i",&a);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
141304 KB |
Output is correct |
2 |
Correct |
88 ms |
141304 KB |
Output is correct |
3 |
Correct |
89 ms |
141304 KB |
Output is correct |
4 |
Correct |
88 ms |
141304 KB |
Output is correct |
5 |
Correct |
89 ms |
141304 KB |
Output is correct |
6 |
Correct |
89 ms |
141304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
141304 KB |
Output is correct |
2 |
Correct |
88 ms |
141304 KB |
Output is correct |
3 |
Correct |
89 ms |
141304 KB |
Output is correct |
4 |
Correct |
88 ms |
141304 KB |
Output is correct |
5 |
Correct |
89 ms |
141304 KB |
Output is correct |
6 |
Correct |
89 ms |
141304 KB |
Output is correct |
7 |
Correct |
97 ms |
141304 KB |
Output is correct |
8 |
Correct |
100 ms |
141388 KB |
Output is correct |
9 |
Correct |
104 ms |
141304 KB |
Output is correct |
10 |
Correct |
99 ms |
141304 KB |
Output is correct |
11 |
Correct |
104 ms |
141308 KB |
Output is correct |
12 |
Correct |
103 ms |
141304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
141308 KB |
Output is correct |
2 |
Correct |
92 ms |
141688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
141304 KB |
Output is correct |
2 |
Correct |
88 ms |
141304 KB |
Output is correct |
3 |
Correct |
89 ms |
141304 KB |
Output is correct |
4 |
Correct |
88 ms |
141304 KB |
Output is correct |
5 |
Correct |
89 ms |
141304 KB |
Output is correct |
6 |
Correct |
89 ms |
141304 KB |
Output is correct |
7 |
Correct |
97 ms |
141304 KB |
Output is correct |
8 |
Correct |
100 ms |
141388 KB |
Output is correct |
9 |
Correct |
104 ms |
141304 KB |
Output is correct |
10 |
Correct |
99 ms |
141304 KB |
Output is correct |
11 |
Correct |
104 ms |
141308 KB |
Output is correct |
12 |
Correct |
103 ms |
141304 KB |
Output is correct |
13 |
Correct |
88 ms |
141308 KB |
Output is correct |
14 |
Correct |
92 ms |
141688 KB |
Output is correct |
15 |
Correct |
93 ms |
141372 KB |
Output is correct |
16 |
Correct |
102 ms |
141436 KB |
Output is correct |
17 |
Correct |
91 ms |
141432 KB |
Output is correct |
18 |
Correct |
94 ms |
141684 KB |
Output is correct |
19 |
Correct |
103 ms |
141304 KB |
Output is correct |
20 |
Correct |
260 ms |
141304 KB |
Output is correct |
21 |
Correct |
188 ms |
141560 KB |
Output is correct |
22 |
Correct |
136 ms |
141432 KB |
Output is correct |
23 |
Correct |
127 ms |
141432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
141688 KB |
Output is correct |
2 |
Runtime error |
2927 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
141304 KB |
Output is correct |
2 |
Correct |
88 ms |
141304 KB |
Output is correct |
3 |
Correct |
89 ms |
141304 KB |
Output is correct |
4 |
Correct |
88 ms |
141304 KB |
Output is correct |
5 |
Correct |
89 ms |
141304 KB |
Output is correct |
6 |
Correct |
89 ms |
141304 KB |
Output is correct |
7 |
Correct |
97 ms |
141304 KB |
Output is correct |
8 |
Correct |
100 ms |
141388 KB |
Output is correct |
9 |
Correct |
104 ms |
141304 KB |
Output is correct |
10 |
Correct |
99 ms |
141304 KB |
Output is correct |
11 |
Correct |
104 ms |
141308 KB |
Output is correct |
12 |
Correct |
103 ms |
141304 KB |
Output is correct |
13 |
Correct |
88 ms |
141308 KB |
Output is correct |
14 |
Correct |
92 ms |
141688 KB |
Output is correct |
15 |
Correct |
93 ms |
141372 KB |
Output is correct |
16 |
Correct |
102 ms |
141436 KB |
Output is correct |
17 |
Correct |
91 ms |
141432 KB |
Output is correct |
18 |
Correct |
94 ms |
141684 KB |
Output is correct |
19 |
Correct |
103 ms |
141304 KB |
Output is correct |
20 |
Correct |
260 ms |
141304 KB |
Output is correct |
21 |
Correct |
188 ms |
141560 KB |
Output is correct |
22 |
Correct |
136 ms |
141432 KB |
Output is correct |
23 |
Correct |
127 ms |
141432 KB |
Output is correct |
24 |
Correct |
96 ms |
141688 KB |
Output is correct |
25 |
Runtime error |
2927 ms |
262148 KB |
Execution killed with signal 9 |
26 |
Halted |
0 ms |
0 KB |
- |