Submission #772299

#TimeUsernameProblemLanguageResultExecution timeMemory
772299NK_Matching (CEOI11_mat)C++17
100 / 100
617 ms45108 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) #define pb push_back // using ll = long long; template<class T> using V = vector<T>; const int MOD1 = int(1e9)+7; // const int MOD2 = 998244353; const int base = int(1e6) + 1007; const int nax = (1 << 20); int POW1[nax], A[nax], B[nax]; // int POW2[nax]; struct T { int H1,/* H2,*/ len; bool operator==(const T &a) { return a.H1 == H1/* && a.H2 == H2*/; }; }; T c; T comb(const T &a, const T &b) { c = a; c.len += b.len; c.H1 = ((a.H1 * 1LL * POW1[b.len]) + b.H1) % MOD1; // c.H2 = ((a.H2 * 1LL * POW2[b.len]) + b.H2) % MOD2; return c; } // SEGTREE T seg[2*nax]; void pull(const int &x) { seg[x] = comb(seg[2*x], seg[2*x+1]); } void upd(int p, const T &v) { seg[p += nax] = v; for(p /= 2; p; p /= 2) pull(p); } T get() { return seg[1]; } int main() { cin.tie(0)->sync_with_stdio(0); for(int t = 0; t < 2*nax; t++) seg[t] = T{0, 0}; int N, M; cin >> N >> M; for(int i = 0; i < N; i++) { cin >> A[i]; --A[i]; } for(int i = 0; i < M; i++) { cin >> B[i]; POW1[i] = B[i]; } sort(POW1, POW1 + M); for(int i = 0; i < M; i++) { B[i] = lower_bound(POW1, POW1 + M, B[i]) - POW1; } // PRE-COMPUTE POW1[0] = 1; // POW2[0] = 1; for(int t = 1; t < nax; t++) { POW1[t] = (POW1[t - 1] * 1LL * base) % MOD1; // POW2[t] = (POW2[t - 1] * 1LL * base) % MOD2; } T H = T{0, 0}, R = T{0, 0}, REM = T{0, 0}; for(int i = 0; i < N; i++) { H = comb(H, T{A[i] + 1, 1}); R = comb(R, T{1, 1}); } V<int> ans; for(int i = 0; i < N; i++) upd(B[i], T{i + 1, 1}); auto check = [&](int i) { T res = get(); if ((res.H1 -= REM.H1) < 0) res.H1 += MOD1; // if ((res.H2 -= REM.H2) < 0) res.H2 += MOD2; if (res == H) ans.push_back(i); }; check(0); for(int i = N; i < M; i++) { if ((REM.H1 += R.H1) >= MOD1) REM.H1 -= MOD1; // if ((REM.H2 += R.H2) >= MOD2) REM.H2 -= MOD2; upd(B[i], T{i + 1, 1}); upd(B[i - N], T{0, 0}); check(i - N + 1); } cout << sz(ans) << nl; for(auto& x : ans) cout << x+1 << " "; cout << nl; return 0; }
#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...