#include <bits/stdc++.h>
using namespace std;
#define int unsigned
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define isz(a) (int)(a).size()
const int NM = 1e6;
int n, m, p[NM+5], h[NM+5], pw[NM+5];
vector <int> arr, ans;
pii st[4*NM+5];
void update(int id, int l, int r, int i, int val){
if (i < l || i > r) return;
if (l == r){
st[id].fi = val > 0;
st[id].se = val;
return;
}
int mid = (l+r)/2;
update(2*id, l, mid, i, val);
update(2*id+1, mid+1, r, i, val);
st[id] = mp(st[2*id].fi+st[2*id+1].fi, st[2*id].se*pw[st[2*id+1].fi]+st[2*id+1].se);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++){
scanf("%d", &p[i]);
p[i]--;
}
for (int i = 1; i <= m; i++){
scanf("%d", &h[i]);
arr.push_back(h[i]);
}
sort(arr.begin(), arr.end());
for (int i = 1; i <= m; i++) h[i] = lower_bound(arr.begin(), arr.end(), h[i])-arr.begin()+1;
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = 1LL*pw[i-1]*n;
int target_res = 0, tmp = 0;
for (int i = 1; i <= n; i++){
target_res = target_res*n+p[i];
tmp = tmp*n+1;
}
for (int i = 1; i <= n; i++) update(1, 1, m, h[i], i);
if (st[1].se-tmp == target_res) ans.push_back(1);
for (int i = 2; i+n-1 <= m; i++){
update(1, 1, m, h[i-1], 0);
update(1, 1, m, h[i+n-1], i+n-1);
if (st[1].se-i*tmp == target_res) ans.push_back(i);
}
printf("%d\n", isz(ans));
for (int x : ans) printf("%d ", x);
return 0;
}
Compilation message (stderr)
mat.cpp: In function 'int main()':
mat.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
mat.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d", &p[i]);
| ~~~~~^~~~~~~~~~~~~
mat.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d", &h[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |