Submission #737215

# Submission time Handle Problem Language Result Execution time Memory
737215 2023-05-06T23:18:44 Z Olympia Zoltan (COCI16_zoltan) C++17
0 / 140
634 ms 34060 KB
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <map>
#include <deque>
using namespace std;
struct Node {
    int mx = 0;
    int cnt = 0; 
    Node (int mx, int cnt) {
        this->mx = mx, this->cnt = cnt;
    }
};
struct SegmentTree {
    vector<Node> vec;
    Node id = Node(-1, -1);
    Node merge (Node left, Node right) {
        if (left.mx == -1) return right;
        if (right.mx == -1) return left;
        if (left.mx > right.mx) return left;
        if (left.mx < right.mx) return right;
        left.cnt += right.cnt;
        return left;
    }   
    Node query (int dum, int tl, int tr, int l, int r) {
        if (tl >= l and tr <= r) {
            return vec[dum];
        } 
        if (r < tl or tr < l) {
            return id;
        }
        return merge(query(2 * dum + 1, tl, (tl + tr)/2, l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r));
    }
    Node query (int l, int r) {
        return query(0, 0, (int)vec.size()/2 - 1, l, r);
    }
    void update (int dum, Node node) {
        dum += (int)vec.size()/2 - 1;
        vec[dum] = node;
        while (dum != 0) {
            dum = (dum - 1)/2;
            vec[dum] = merge(vec[2 * dum + 1], vec[2 * dum + 2]);
        }
    }
    SegmentTree (int n) {
        n = (1 << (int)log2(n)) * 2;
        vec.assign(2 * n, id);
    }
};
vector<Node> lis (vector<int>& v) {
    SegmentTree st(v.size());
    map<int,vector<int>> oc;
    for (int i = 0; i < v.size(); i++) {
        oc[v[i]].push_back(i);
    }
    vector<Node> vec;
    vec.push_back(Node(0, 1));
    int used = pow(2, v.size() - 1);
    for (auto& p: oc) {
        vector<Node> upd;
        for (int i: p.second) {
            Node node = st.query(0, i - 1);
            if (node.mx == -1) {
                node = Node(1, 1);
            } else {
                node.mx += 1;
            }
            upd.push_back(node);
        }
        reverse(upd.begin(), upd.end());
        for (int i: p.second) {
            st.update(i, upd.back()), upd.pop_back();
        }
        for (int i = 0; i < p.second.size(); i++) {
            used /= 2;
        }
        vec.emplace_back(st.query(0, (int)v.size() - 1));
        //vec.back().cnt *= pow(2, (int)v.size() - vec.back().mx);
    }
    return vec;
}
vector<Node> lds (vector<int>& v) {
    SegmentTree st(v.size());
    map<int,vector<int>> oc;
    for (int i = 0; i < v.size(); i++) {
        oc[-v[i]].push_back(i);
    }
    vector<Node> vec;
    vec.push_back(Node(0, 1));
    for (auto& p: oc) {
        vector<Node> upd;
        for (int i: p.second) {
            Node node = st.query(i + 1, (int)v.size() - 1);
            if (node.mx == -1) {
                node = Node(1, 1);
            } else {
                node.mx += 1;
            }
            upd.push_back(node);
        }
        reverse(upd.begin(), upd.end());
        for (int i: p.second) {
            st.update(i, upd.back()), upd.pop_back();
        }
        vec.emplace_back(st.query(0, (int)v.size() - 1));
        //vec.back().cnt *= pow(2, (int)v.size() - vec.back().mx);
    }
    reverse(vec.begin(), vec.end());
    return vec;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    auto a1 = lds(v);
    auto a2 = lis(v);
    int mx = 0, cnt = 0;
    for (int i = 0; i < a1.size(); i++) {
        if (a1[i].mx + a2[i].mx > mx) {
            mx = a1[i].mx + a2[i].mx;
            cnt = a1[i].cnt * a2[i].cnt;
        } else if (a1[i].mx + a2[i].mx == mx) {
            cnt += a1[i].cnt * a2[i].cnt;
        }
    }
    cout << mx << " " << cnt;
}

Compilation message

zoltan.cpp: In function 'std::vector<Node> lis(std::vector<int>&)':
zoltan.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
zoltan.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int i = 0; i < p.second.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
zoltan.cpp: In function 'std::vector<Node> lds(std::vector<int>&)':
zoltan.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
zoltan.cpp: In function 'int main()':
zoltan.cpp:130:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     for (int i = 0; i < a1.size(); i++) {
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 2 ms 468 KB Output isn't correct
8 Incorrect 2 ms 468 KB Output isn't correct
9 Incorrect 2 ms 468 KB Output isn't correct
10 Incorrect 2 ms 452 KB Output isn't correct
11 Incorrect 327 ms 28004 KB Output isn't correct
12 Incorrect 264 ms 25136 KB Output isn't correct
13 Incorrect 244 ms 21016 KB Output isn't correct
14 Incorrect 411 ms 25628 KB Output isn't correct
15 Incorrect 530 ms 30260 KB Output isn't correct
16 Runtime error 634 ms 34060 KB Memory limit exceeded
17 Incorrect 374 ms 29508 KB Output isn't correct
18 Incorrect 385 ms 29384 KB Output isn't correct
19 Incorrect 376 ms 29488 KB Output isn't correct
20 Incorrect 377 ms 29400 KB Output isn't correct