제출 #483321

#제출 시각아이디문제언어결과실행 시간메모리
483321BERNARB01Lottery (CEOI18_lot)C++17
45 / 100
1396 ms65540 KiB
#include <bits/stdc++.h> using namespace std; const int N = 10004; const int b = (int) 1e9 + 7; const int mod = (int) 1e9 + 9; const int b2 = (int) 1e9 + 9; const int mod2 = (int) 1e9 + 21; int n, l, a[N], q; long long pb[N], h[N]; long long pb2[N], h2[N]; vector<int> v[N]; inline pair<int, int> get(int ql, int qr) { return { pb[n - ql] * 1LL * (h[qr + 1] - h[ql] + mod) % mod, pb2[n - ql] * 1LL * (h2[qr + 1] - h2[ql] + mod2) % mod2 }; } int mat(int s, int ss) { int k = 0; for (int i = 0; i < l; i++) { if (a[s + i] != a[ss + i]) { k += 1; continue; } if (get(s + i, s + l - 1) == get(ss + i, ss + l - 1)) { break; } int lb = 1, r = l + 1 - i; while (r - lb > 1) { int mid = (lb + r) >> 1; if (get(s + i, s + i + mid - 1) == get(ss + i, ss + i + mid - 1)) { lb = mid; } else { r = mid; } } i += lb; k += 1; } return k; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> l; for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> q; pb[0] = 1; pb2[0] = 1; for (int i = 1; i <= n; i++) { pb[i] = pb[i - 1] * 1LL * b % mod; pb2[i] = pb2[i - 1] * 1LL * b2 % mod2; } for (int i = 0; i < n; i++) { h[i + 1] = (pb[i] * 1LL * a[i] % mod + h[i]) % mod; h2[i + 1] = (pb2[i] * 1LL * a[i] % mod2 + h2[i]) % mod2; } for (int i = 0; i + l <= n; i++) { for (int j = i + 1; j + l <= n; j++) { int c = mat(i, j); v[i].push_back(c); v[j].push_back(c); } } for (int i = 0; i + l <= n; i++) { sort(v[i].begin(), v[i].end()); } while (q--) { int k; cin >> k; for (int i = 0; i + l <= n; i++) { if (i > 0) { cout << " "; } cout << upper_bound(v[i].begin(), v[i].end(), k) - v[i].begin(); } cout << '\n'; } 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...