Submission #835407

# Submission time Handle Problem Language Result Execution time Memory
835407 2023-08-23T14:12:16 Z otarius Exam (eJOI20_exam) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

// #define int long long
// #define int unsigned long long

const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;

void solve() {
    int n;
    cin >> n;
    int seg[n + 1][2];
    for (int i = 0; i <= n; i++)
        seg[i][0] = seg[i][1] = 0;
    vector<int> a(n);
    vector<int> b(n);
    for (int &v : a) cin >> v;
    for (int &v : b) cin >> v;
    map<int, int> cont; stack<int> st;
    for (int i = 0; i < n; i++) {
        while (!st.empty() && st.top() <= a[i]) {
            cont.erase(st.top()); st.pop();
        } cont[a[i]] = i; st.push(a[i]);
        if (cont.find(b[i]) != cont.end())
            seg[i][0] = cont[b[i]];
    } cont.clear(); while (!st.empty()) st.pop();
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() && st.top() <= a[i]) {
            cont.erase(st.top()); st.pop();
        } cont[a[i]] = i; st.push(a[i]);
        if (cont.find(b[i]) != cont.end())
            seg[i][1] = cont[b[i]];
    } vector<int> vec, lis;
    for (int i = 0; i < n; i++) {
        if (seg[i][1] != -1) vec.pb(seg[i][1]);
        if (seg[i][0] != -1 && seg[i][0] != seg[i][1]) vec.pb(seg[i][0]);
    } for (int v : vec) {
        auto it = upper_bound(vec.begin(), vec.end(), v);
        if (it == vec.end()) lis.pb(v);
        else *it = v;
    } cout << lis.size();
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

exam.cpp: In function 'void solve()':
exam.cpp:36:25: error: 'stack' was not declared in this scope
   36 |     map<int, int> cont; stack<int> st;
      |                         ^~~~~
exam.cpp:10:1: note: 'std::stack' is defined in header '<stack>'; did you forget to '#include <stack>'?
    9 | #include <iomanip>
  +++ |+#include <stack>
   10 | using namespace std;
exam.cpp:36:31: error: expected primary-expression before 'int'
   36 |     map<int, int> cont; stack<int> st;
      |                               ^~~
exam.cpp:38:17: error: 'st' was not declared in this scope; did you mean 'std'?
   38 |         while (!st.empty() && st.top() <= a[i]) {
      |                 ^~
      |                 std
exam.cpp:40:27: error: 'st' was not declared in this scope; did you mean 'std'?
   40 |         } cont[a[i]] = i; st.push(a[i]);
      |                           ^~
      |                           std
exam.cpp:43:29: error: 'st' was not declared in this scope; did you mean 'std'?
   43 |     } cont.clear(); while (!st.empty()) st.pop();
      |                             ^~
      |                             std
exam.cpp:45:17: error: 'st' was not declared in this scope; did you mean 'std'?
   45 |         while (!st.empty() && st.top() <= a[i]) {
      |                 ^~
      |                 std
exam.cpp:47:27: error: 'st' was not declared in this scope; did you mean 'std'?
   47 |         } cont[a[i]] = i; st.push(a[i]);
      |                           ^~
      |                           std