Submission #1187463

#TimeUsernameProblemLanguageResultExecution timeMemory
1187463nevuorigMatching (CEOI11_mat)C++17
0 / 100
851 ms72428 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll int
#define ld long double
#define str string

#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()

#define in insert

#define fi first
#define se second

#define size size()

#define begin begin()
#define end end()
#define back back()
#define front front()
#define rend rend()
#define rbegin rbegin()


#define ret return

#define ull unsigned long long

#define all(a) a.begin , a.end

#define gcd __gcd

#define lcm(a , b) (a * b) / gcd(a , b)

#define friopen freopen ("exercise.in", "r", stdin); freopen("exercise.out", "w", stdout);

using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const ll mod = 1e9 + 7 , mod2 = 998244353 , N = 1e6 , inf = 1e18;
const ld esp = 0.0000001 , Pi = 3.1415926535897932384626433832795;


ll p[N + 12] , node[4 * N + 12] , s[4 * N + 12];

void update(ll ind , ll v , ll x = 1 , ll l = 1 , ll r = N)
{
	if (r < ind || l > ind) ret ;
	if (l == r)
	{
		// cout<<l<<endl;
		node[x] = v;
		s[x] = (v != 0);
		ret;
	}
	else
	{
		ll m = (l + r) / 2;
		update(ind , v , 2 * x , l , m);
		update(ind , v , 2 * x + 1 , m + 1 , r);
		node[x] = (node[2 * x]*1LL + (node[2 * x + 1]*1LL * p[s[2 * x]]%mod * 1LL) % mod) % mod;
		s[x] = s[2 * x] + s[2 * x + 1];
	}
}

void kol_a()
{
	ll n , m , i , j;
	cin >> n >> m;
	deque<ll> ans;
	ll a[n + 12] = {} , b[m + 12] = {};
	for (i = 1 ; i <= n ; i ++) cin >> a[i];
	for (i = 1 ; i <= m ; i ++) cin >> b[i];
	p[0] = 1;
	for (i = 1 ; i <= m ; i ++) p[i] = (37LL * p[i - 1]) % mod;
	map<ll , ll> us;
	ll t = 1 , v1 = 0 , v2 = 0;
	for (i = 1 ; i <= m ; i ++) us[b[i]] = i;
	
	for (auto &x : us) b[x.se]=t++;
	
	
	for (i = 1 ; i <= n ; i ++)
	{
		v1 = (v1*1LL + (a[i] * p[i - 1])%mod ) % mod;
		v2 = (v2*1LL +p[i - 1])%mod;
	}
	
	
	for (i = 1 ; i <= n ; i ++) update(b[i] , i);
	
	
	if (v1 == node[1]) ans.pb(1);
	for (i = 2 ; i + n - 1 <= m ; i ++)
	{
		update(b[i - 1] , 0);
		update(b[i + n - 1] , i + n - 1);
		v1 = (v1 + v2*1LL) % mod;
		if (v1 == node[1]){ ans.pb(i);}
	}
	cout << ans.size << '\n';
	for (auto x : ans) cout << x << " ";
	cout<<endl;
}


main()
{
	// friopen
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll _ = 1;

	
	
    while(_ --) kol_a();
}


/*



*/

Compilation message (stderr)

mat.cpp:45:61: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   45 | const ll mod = 1e9 + 7 , mod2 = 998244353 , N = 1e6 , inf = 1e18;
      |                                                             ^~~~
mat.cpp:112:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  112 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...