제출 #204511

#제출 시각아이디문제언어결과실행 시간메모리
204511SaboonMatching (CEOI11_mat)C++14
100 / 100
926 ms40436 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 10; int a[maxn], b[maxn], h[maxn]; int fen[maxn]; int f[maxn]; int get(int idx){ int ret = 0; for (; idx; idx -= idx & -idx) ret += fen[idx]; return ret; } void add(int idx, int val){ for (; idx < maxn; idx += idx & -idx) fen[idx] += val; } int main(){ ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++){ int x; cin >> x; a[x - 1] = i; } vector<int> cmp; for (int i = 0; i < m; i++){ cin >> h[i]; cmp.push_back(h[i]); } sort(cmp.begin(), cmp.end()); for (int i = 0; i < m; i++) h[i] = lower_bound(cmp.begin(), cmp.end(), h[i]) - cmp.begin() + 1; for (int i = 0; i < n; i++){ add(a[i], +1); b[i] = get(a[i]); } for (int i = 0; i < n; i++) add(a[i], -1); // vitex f[0] = f[1] = 0; int k = 0; for (int i = 1; i < n; i++){ add(a[i], +1); int now = get(a[i]); while (k > 0 and b[k] != now){ for (int t = i - k; t < i - f[k]; t++) add(a[t], -1); k = f[k]; now = get(a[i]); } k += (b[k] == now); f[i + 1] = k; } memset(fen, 0, sizeof fen); vector<int> ans; k = 0; for (int i = 0; i < m; i++){ add(h[i], +1); int now = get(h[i]); while (k > 0 and b[k] != now){ for (int t = i - k; t < i - f[k]; t++) add(h[t], -1); k = f[k]; now = get(h[i]); } k += (b[k] == now); if (k == n){ ans.push_back(i - k + 1); for (int t = i - k + 1; t < i - f[k] + 1; t++) add(h[t], -1); k = f[k]; } } cout << ans.size() << '\n'; for (auto it : ans) cout << it + 1 << " "; cout << endl; }
#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...