제출 #986945

#제출 시각아이디문제언어결과실행 시간메모리
986945LOLOLOMatching (CEOI11_mat)C++17
63 / 100
2610 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 1e6 + 10; const int mod = 1e9 + 7; const int base = 1000037; int seg[N * 2], sz[N * 2], pw[N], p[N], a[N]; int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int mul(int a, int b) { return ((ll)a * b) % mod; } void upd(int id, int l, int r, int p, int v) { if (l == r) { seg[id] = v; sz[id] = bool(v); } else { int m = (l + r) / 2; if (m >= p) { upd(id * 2, l, m, p, v); } else { upd(id * 2 + 1, m + 1, r, p, v); } sz[id] = sz[id * 2] + sz[id * 2 + 1]; seg[id] = add(seg[id * 2], mul(pw[sz[id * 2]], seg[id * 2 + 1])); } } void zip(int n) { vector <pair <int, int>> save; for (int i = 1; i <= n; i++) { save.pb({a[i], i}); } sort(all(save)); int cnt = 1; for (int i = 0; i < n; i++) { a[save[i].s] = cnt; cnt++; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; pw[0] = 1; for (int i = 1; i <= m; i++) { pw[i] = mul(pw[i - 1], base); } for (int i = 1; i <= n; i++) { int s; cin >> s; p[i] = s; } int hash = 0, sum = 0; for (int i = 1; i <= n; i++) { hash = add(hash, mul(pw[i - 1], p[i])); sum = add(sum, pw[i - 1]); } for (int i = 1; i <= m; i++) { cin >> a[i]; } zip(m); vector <int> res; for (int i = 1; i < n; i++) { upd(1, 1, m, a[i], i); } for (int i = n; i <= m; i++) { upd(1, 1, m, a[i], i); if (seg[1] == hash) { res.pb(i - n + 1); } upd(1, 1, m, a[i - n + 1], 0); hash = add(hash, sum); } cout << sz(res) << '\n'; for (auto x : res) cout << x << " "; return 0; } /* 5 10 2 1 5 3 4 6 3 8 12 7 1 10 11 9 5 */
#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...