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;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6;
const int mod = 1e9 + 7;
const int base = 1000037;
int seg[2097149 + 1], sz[2097149 + 1], pw[N + 1], p[N], a[N];
int add(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int mul(int a, int b) {
return ((ll)a * b) % mod;
}
void upd(int id, int l, int r, int p, int v) {
if (l == r) {
seg[id] = v;
sz[id] = bool(v);
} else {
int m = (l + r) / 2;
if (m >= p) {
upd(id * 2, l, m, p, v);
} else {
upd(id * 2 + 1, m + 1, r, p, v);
}
sz[id] = sz[id * 2] + sz[id * 2 + 1];
seg[id] = add(seg[id * 2], mul(pw[sz[id * 2]], seg[id * 2 + 1]));
}
}
void zip(int n) {
vector <pair <int, int>> save;
for (int i = 1; i <= n; i++) {
save.pb({a[i], i});
}
sort(all(save));
int cnt = 1;
for (int i = 0; i < n; i++) {
a[save[i].s] = cnt;
cnt++;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
pw[0] = 1;
for (int i = 1; i <= m; i++) {
pw[i] = mul(pw[i - 1], base);
}
for (int i = 1; i <= n; i++) {
int s;
cin >> s;
p[i] = s;
}
int hash = 0, sum = 0;
for (int i = 1; i <= n; i++) {
hash = add(hash, mul(pw[i - 1], p[i]));
sum = add(sum, pw[i - 1]);
}
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
zip(m);
vector <int> res;
for (int i = 1; i < n; i++) {
upd(1, 1, m, a[i], i);
}
for (int i = n; i <= m; i++) {
upd(1, 1, m, a[i], i);
if (seg[1] == hash) {
res.pb(i - n + 1);
}
upd(1, 1, m, a[i - n + 1], 0);
hash = add(hash, sum);
}
cout << sz(res) << '\n';
for (auto x : res)
cout << x << " ";
return 0;
}
/*
5 10
2 1 5 3 4
6 3 8 12 7 1 10 11 9 5
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |