#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>
using namespace std;
bool START_ALLOC;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int MAX = 2e6 + 15;
int n, m;
int a[MAX], b[MAX];
int bit[MAX];
ll base = 0;
void update(int idx, int v){
for(;idx < MAX; idx += idx & -idx) bit[idx] += v;
}
int query(int idx){
int res = 0;
for(;idx; idx -= idx & -idx) res += bit[idx];
return res;
}
int upper(int x, int bound){
return query(bound) - query(x);
}
int lower(int x){
return query(x-1);
}
vector<int> compress;
void solve(){
cin >> n >> m;
if(m < n){
cout << 0 << endl;
return;
}
for(int i = 1; i <= n; i++){
cin >> a[i];
base += upper(a[i], MAX-1);
update(a[i], 1);
}
for(int i = 1; i <= n; i++){
update(a[i], -1);
}
for(int i = 1; i <= m; i++){
cin >> b[i];
compress.push_back(b[i]);
}
sort(all(compress)); compact(compress);
for(int i = 1; i <= m; i++){
b[i] = lower_bound(all(compress), b[i]) - compress.begin() + 1;
}
ll cur = 0;
for(int i = 1; i <= n; i++){
cur += upper(b[i], MAX-1);
update(b[i], 1);
}
vector<int> ans;
if(cur == base) ans.push_back(1);
for(int i = n+1; i <= m; i++){
cur -= lower(b[i-n]);
update(b[i-n], -1);
cur += upper(b[i], MAX-1);
update(b[i], 1);
if(cur == base) ans.push_back(i - n + 1);
}
cout << sz(ans) << endl;
for(int x : ans) cout << x << " ";
}
bool END_ALLOC;
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
cerr << "[Static Memory : " << fixed << setprecision(2) << (((&END_ALLOC) - (&START_ALLOC)) / (1024.0 * 1024.0)) << "mb]\n";
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
mat.cpp: In function 'int main()':
mat.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mat.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
115 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |