제출 #772298

#제출 시각아이디문제언어결과실행 시간메모리
772298NK_Matching (CEOI11_mat)C++17
63 / 100
262 ms65536 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 = ll(1e9)+7; // const int MOD2 = 998244353; const int base = int(1e6) + 1007; const int nax = (1 << 20); int POW1[nax]; // int POW2[nax]; struct T { int H1,/* H2,*/ len; bool operator==(T a) { return a.H1 == H1/* && a.H2 == H2*/; }; }; T c; T comb(T a, 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(int x) { seg[x] = comb(seg[2*x], seg[2*x+1]); } void upd(int p, 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); 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; } for(int t = 0; t < 2*nax; t++) seg[t] = T{0, 0}; int N, M; cin >> N >> M; V<int> A(N); for(auto& x : A) { cin >> x; --x; } V<int> B(M); for(auto& x : B) cin >> x; { map<int, int> mp; int cur = 0; for(auto& x : B) mp[x]++; for(auto& p : mp) p.second = cur++; for(auto& x : B) x = mp[x]; } T H = {0, 0}, R = {0, 0}, REM = {0, 0}; for(int i = 0; i < N; i++) { H = comb(H, {A[i] + 1, 1}); R = comb(R, {1, 1}); } V<int> ans; for(int i = 0; i < N; i++) upd(B[i], {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], {i + 1, 1}); upd(B[i - N], {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...