제출 #937818

#제출 시각아이디문제언어결과실행 시간메모리
937818_callmelucianMatching (CEOI11_mat)C++14
100 / 100
321 ms57568 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 BIT { vector<int> tr; BIT (int sz) : tr(sz + 1, INT_MIN) {} int p (int k) { return k & -k; } void update (int k, int val) { for (; k < tr.size(); k += p(k)) tr[k] = max(tr[k], val); } int query (int k, int ans = INT_MIN) { for (; k; k -= p(k)) ans = max(ans, tr[k]); return ans; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> pos(n + 1), s(n), h(m); for (int i = 1; i <= n; i++) { cin >> pos[i]; s[--pos[i]] = i; } for (int i = 0; i < m; i++) cin >> h[i]; s.push_back(INT_MAX); for (int u : h) s.push_back(u); vector<int> lower(n), upper(n), pi(n + m + 1), ans; BIT lw(n + 1), up(n + 1); for (int i = 0; i < n; i++) { int lb = lw.query(s[i]), ub = up.query(n - s[i] + 1); lower[i] = (lb == INT_MIN ? -1 : i - pos[lb]); upper[i] = (ub == INT_MIN ? -1 : i - pos[-ub]); lw.update(s[i], s[i]); up.update(n - s[i] + 1, -s[i]); } function<bool(int,int)> ok = [&] (int j, int i) { if (max(s[j], s[i]) == INT_MAX) return 0; if (lower[j] != -1) if (s[i - lower[j]] > s[i]) return 0; if (upper[j] != -1) if (s[i - upper[j]] < s[i]) return 0; return 1; }; for (int i = 1; i < n + m + 1; i++) { int j = pi[i - 1]; while (j && !ok(j, i)) j = pi[j - 1]; if (ok(j, i)) pi[i] = j + 1; if (pi[i] == n) ans.push_back(i - 2 * n + 1); } cout << ans.size() << "\n"; for (int u : ans) cout << u << " "; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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