Submission #936938

#TimeUsernameProblemLanguageResultExecution timeMemory
936938_callmelucianMatching (CEOI11_mat)C++17
63 / 100
389 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) struct pBIT { vector<vector<pii>> tr; pBIT (int sz) : tr(sz + 1, vector<pii>(1, make_pair(-1, 0))) {} int get (int k, int ver) { auto it = upper_bound(all(tr[k]), make_pair(ver, INT_MAX)); return prev(it)->second; } int p (int k) { return k & -k; } void update (int k, int val, int ver) { for (; k < tr.size(); k += p(k)) { int cur = tr[k].back().second + val; tr[k].push_back(make_pair(ver, cur)); } } int query (int k, int ver, int ans = 0) { for (; k; k -= p(k)) ans += get(k, ver); return ans; } }; struct BIT { vector<int> tr; BIT (int sz) : tr(sz + 1) {} int p (int k) { return k & -k; } void update (int k, int val) { for (; k < tr.size(); k += p(k)) tr[k] += val; } int query (int k, int ans = 0) { for (; k; k -= p(k)) ans += tr[k]; return ans; } }; vector<int> mp; void compress() { sort(all(mp)); filter(mp); } int getID (int u) { return lower_bound(all(mp), u) - mp.begin() + 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> s(n), h(m); for (int i = 1; i <= n; i++) { int p; cin >> p; s[p - 1] = i; } for (int i = 0; i < m; i++) { cin >> h[i]; mp.push_back(h[i]); } compress(); vector<int> vec = s; vec.push_back(INT_MAX); for (int u : h) vec.push_back(getID(u)); /* prefix function */ int sz = vec.size(); vector<int> pi(sz), pre(sz), ans; pBIT tree(max(n, m)); for (int i = 0; i < sz; i++) if (vec[i] < INT_MAX) tree.update(vec[i], 1, i); BIT helper(sz); for (int i = 0; i < sz; i++) { if (vec[i] == INT_MAX) continue; helper.update(vec[i], 1); pre[i] = helper.query(vec[i]); } function<bool(int,int)> same = [&] (int i, int j) { // [0..i-1] + i == [j-i..j-1] + j if (vec[i] == INT_MAX || vec[j] == INT_MAX) return false; return pre[i] == (pre[j] - tree.query(vec[j], j - i - 1)); }; for (int i = 1; i < sz; i++) { int j = pi[i - 1]; while (j && !same(j, i)) j = pi[j - 1]; if (same(j, i)) pi[i] = j + 1; } /* prefix function */ for (int i = 0; i < pi.size(); i++) if (pi[i] == n) ans.push_back(i - 2 * n + 1); cout << ans.size() << "\n"; for (int u : ans) cout << u << " "; return 0; }

Compilation message (stderr)

mat.cpp: In member function 'void pBIT::update(int, int, int)':
mat.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (; k < tr.size(); k += p(k)) {
      |                ~~^~~~~~~~~~~
mat.cpp: In member function 'void BIT::update(int, int)':
mat.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (; k < tr.size(); k += p(k))
      |                ~~^~~~~~~~~~~
mat.cpp: In function 'int main()':
mat.cpp:112:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |     for (int i = 0; i < pi.size(); i++)
      |                     ~~^~~~~~~~~~~
#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...