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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("fast-math")
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int M = 1000100;
const int N = 110;
const int md = int(1e9) + 7;
bitset<N> was[M], mrk;
int a[M], n, m, ans[M], pf[M], bb[M];
int mult(int x, int y) { return (1ll * x * y) % md; }
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int sub(int x, int y){
x -= y;
if (x < 0)
x += md;
return x;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a[i];
bb[i - 1] = a[i];
}
ans[0] = 0;
pf[0] = 0;
for (int i = 1; i < m; i++){
int j = pf[i - 1];
while (j > 0 && bb[i] != bb[j])
j = pf[j - 1];
if (bb[i] == bb[j])
j++;
pf[i] = j;
}
// aut[0][a[1]] = 1;
for (int i = 1; i <= m; i++){
ans[i] = mult(sum(ans[i - 1], 1), n);
int id = i - 1;
was[i] = was[pf[i]];
was[i][bb[pf[i]]] = 1;
// for (int j = 1; j <= n; j++)
// if (j == bb[id])
// aut[i][j] = id + 1;
// else aut[i][j] = aut[pf[i]][j];
int cnt = was[i].count(), fod = 0;
for (int i = 1; i <= n; i++)
mrk[i] = 0;
int loc = pf[i];
while (fod < cnt){
int cur = bb[loc];
if (!mrk[cur]){
mrk[cur] = 1;
fod++;
ans[i] = sub(ans[i], ans[loc]);
}
loc = pf[loc];
}
// for (int j = 1; j <= n; j++)
// if (a[i] != j){
// int mx = aut[i][j];
//
// ans[i] = sum(ans[i], ans[i - 1]);
// ans[i] = sub(ans[i], ans[mx]);
// ans[i] = sum(ans[i], 1);
// } else {
// ans[i] = sum(ans[i], ans[i - 1] + 1);
// }
cout << ans[i] << '\n';
}
return 0;
}
Compilation message (stderr)
klavir.cpp: In function 'int main()':
klavir.cpp:68:13: warning: unused variable 'id' [-Wunused-variable]
int id = i - 1;
^~
# | 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... |
# | 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... |