Submission #440446

#TimeUsernameProblemLanguageResultExecution timeMemory
440446prvocisloExam (eJOI20_exam)C++17
100 / 100
214 ms13880 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; vector<vector<int> > v(n, vector<int>(2, -1)); for (int it = 0; it < 2; it++) { map<int, int> m; vector<pair<int, int>> stk; // {hodnota, index} for (int k = 0; k < n; k++) { int i = it ? n - k - 1 : k; while (!stk.empty() && a[i] > stk.back().first) m[stk.back().first] = -1, stk.pop_back(); stk.push_back({a[i], i}); m[a[i]] = i; if (m.count(b[i]) && m[b[i]] != -1) v[i][it] = m[b[i]]; } } vector<int> u; for (int i = 0; i < n; i++) { if (v[i][1] != -1) u.push_back(v[i][1]); if (v[i][0] != -1 && v[i][0] != v[i][1]) u.push_back(v[i][0]); } vector<int> l; for (int i : u) { int id = upper_bound(l.begin(), l.end(), i) - l.begin(); if (id == l.size()) l.push_back(i); else l[id] = i; } cout << l.size() << "\n"; return 0; }

Compilation message (stderr)

exam.cpp: In function 'int main()':
exam.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if (id == l.size()) l.push_back(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...