#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10, mod=1e9+7;
int n, a[N], f[N][2];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i=1; i<=n; ++i) cin >> a[i];
map<int, int> mp;
for (int i=1; i<=n; ++i){
++mp[a[i]];
for (auto it=mp.begin(); it!=mp.end();){
if (it!=mp.begin() && prev(it)->first+1==it->first){
int x=it->first;
int d=min(prev(it)->second, it->second);
mp[x+1]+=d;
prev(it)->second-=d;
if (prev(it)->second==0) mp.erase(prev(it));
it->second-=d;
if (it->second==0) it=mp.erase(it);
while (it!=mp.begin() && prev(it)->first>=x-1) --it;
}else if (it->second>=2){
int x=it->first;
int d=it->second/2;
if (x==1){
if (it->second==2){
++mp[2];
it=mp.erase(it);
}else{
mp[3]+=it->second/3;
it->second%=3;
if (it->second==0) it=mp.erase(it);
else ++it;
}
}else if (x==2){
int sum=it->second*2;
mp[3]+=sum/3;
if (sum%3) mp[1]+=sum%3;
mp.erase(it);
it=mp.begin();
}else{
mp[x-2]+=d;
mp[x+1]+=d;
it->second-=d*2;
if (it->second==0) it=mp.erase(it);
while (it!=mp.begin() && prev(it)->first>=x-2) --it;
}
}else ++it;
}
vector<int> v{-1};
for (auto &j:mp) v.push_back(j.first);
f[1][0]=(v[1]+1)/2;
f[1][1]=f[1][0]-1;
for (int j=2; j<(int)v.size(); ++j){
if ((v[j]&1)==(v[j-1]&1)){
f[j][0]=(f[j-1][0]*(v[j]-v[j-1])/2+f[j-1][1]+mod)%mod;
f[j][1]=(f[j][0]-f[j-1][0]+mod)%mod;
}else{
f[j][0]=f[j-1][0]*(v[j]-v[j-1]+1)/2%mod;
f[j][1]=(f[j][0]-f[j-1][0]+mod)%mod;
}
}
cout << f[(int)v.size()-1][0] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Execution timed out |
4040 ms |
4012 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Execution timed out |
4040 ms |
4012 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |