Submission #463753

# Submission time Handle Problem Language Result Execution time Memory
463753 2021-08-11T17:23:06 Z idk321 Global Warming (CEOI18_glo) Java 11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MIN = -2000000001;
const int MAX = 2000000001;

int n, x;
const int N = 200005;
int tree[4 * N][2];

int getMax(int from, int to, int a, int b, int node, int treeNum) {
    if (from > to) return 0;
    if (from <= a && b <= to) return tree[node][treeNum];

    int mid = (a + b) / 2;
    int res = -1;
    if (from <= mid) res = max(res, getMax(from, to, a, mid, node * 2, treeNum));
    if (to > mid) res = max(res, getMax(from, to, mid +1, b, node * 2 + 1, treeNum));

    return res;
}

void insertMax(int i, int num, int a, int b, int node, int treeNum) {
    if (a == b) {
        tree[node][treeNum] = max(tree[node][treeNum], num);
        return;
    }

    int mid = (a + b) / 2;
    if (i <= mid) insertMax(i, num, a, mid, node * 2, treeNum);
    else insertMax(i, num, mid + 1, b, node * 2 + 1, treeNum);
    tree[node][treeNum] = max(tree[node * 2][treeNum], tree[node * 2 + 1][treeNum]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    if (n == 1) {
        cout << 1 << "\n";
        return 0;
    }
    vector<int> left(n);

    set<int> all;
    map<int, int> mapTo;
    for (int i = 0; i < n; i++) all.insert(v[i]);
    int cur = 0;
    for (int i : all) {
        mapTo[i] = cur;
        cur++;
    }

    vector<int> getsTo(n);
    vector<int> org(v.begin(), v.end());
    set<array<int, 2>> orgAndNew;
    for (int i = 0; i < n; i++) {
        v[i] = mapTo[v[i]];
        orgAndNew.insert({org[i], v[i]});
    }

    for (int i = 0; i < n; i++) {
        auto it = orgAndNew.upper_bound({org[i] + x, -1});
        it--;
        getsTo[v[i]] = (*it)[1];
    }

    for (int i = 0; i < n; i++) {
        insertMax(v[i], 1 + getMax(0, getsTo[v[i]], 0, N - 1, 1, 0), 0, N - 1, 1, 1);
        insertMax(v[i], 1 + getMax(0, v[i] - 1, 0, N - 1, 1, 0), 0, N - 1, 1, 0);
        insertMax(v[i], 1 + getMax(0, v[i] - 1, 0, N - 1, 1, 1), 0, N - 1, 1, 1);
    }

    cout << getMax(0, N - 1, 0, N - 1, 1, 1) << "\n";
}

/*
8 10
7 3 5 12 2 7 3 4
*/

Compilation message

glo.java:2: error: illegal character: '#'
#include <bits/stdc++.h>
^
glo.java:2: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
glo.java:4: error: class, interface, or enum expected
typedef long long ll;
^
glo.java:6: error: class, interface, or enum expected
const int MIN = -2000000001;
^
glo.java:7: error: class, interface, or enum expected
const int MAX = 2000000001;
^
glo.java:9: error: class, interface, or enum expected
int n, x;
^
glo.java:10: error: class, interface, or enum expected
const int N = 200005;
^
glo.java:11: error: class, interface, or enum expected
int tree[4 * N][2];
^
glo.java:13: error: class, interface, or enum expected
int getMax(int from, int to, int a, int b, int node, int treeNum) {
^
glo.java:15: error: class, interface, or enum expected
    if (from <= a && b <= to) return tree[node][treeNum];
    ^
glo.java:17: error: class, interface, or enum expected
    int mid = (a + b) / 2;
    ^
glo.java:18: error: class, interface, or enum expected
    int res = -1;
    ^
glo.java:19: error: class, interface, or enum expected
    if (from <= mid) res = max(res, getMax(from, to, a, mid, node * 2, treeNum));
    ^
glo.java:20: error: class, interface, or enum expected
    if (to > mid) res = max(res, getMax(from, to, mid +1, b, node * 2 + 1, treeNum));
    ^
glo.java:22: error: class, interface, or enum expected
    return res;
    ^
glo.java:23: error: class, interface, or enum expected
}
^
glo.java:28: error: class, interface, or enum expected
        return;
        ^
glo.java:29: error: class, interface, or enum expected
    }
    ^
glo.java:32: error: class, interface, or enum expected
    if (i <= mid) insertMax(i, num, a, mid, node * 2, treeNum);
    ^
glo.java:33: error: class, interface, or enum expected
    else insertMax(i, num, mid + 1, b, node * 2 + 1, treeNum);
    ^
glo.java:34: error: class, interface, or enum expected
    tree[node][treeNum] = max(tree[node * 2][treeNum], tree[node * 2 + 1][treeNum]);
    ^
glo.java:35: error: class, interface, or enum expected
}
^
glo.java:39: error: class, interface, or enum expected
    cin.tie(0);
    ^
glo.java:41: error: class, interface, or enum expected
    cin >> n >> x;
    ^
glo.java:42: error: class, interface, or enum expected
    vector<int> v(n);
    ^
glo.java:43: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) cin >> v[i];
    ^
glo.java:43: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) cin >> v[i];
                    ^
glo.java:43: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) cin >> v[i];
                           ^
glo.java:44: error: class, interface, or enum expected
    if (n == 1) {
    ^
glo.java:46: error: class, interface, or enum expected
        return 0;
        ^
glo.java:47: error: class, interface, or enum expected
    }
    ^
glo.java:50: error: class, interface, or enum expected
    set<int> all;
    ^
glo.java:51: error: class, interface, or enum expected
    map<int, int> mapTo;
    ^
glo.java:52: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) all.insert(v[i]);
    ^
glo.java:52: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) all.insert(v[i]);
                    ^
glo.java:52: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) all.insert(v[i]);
                           ^
glo.java:53: error: class, interface, or enum expected
    int cur = 0;
    ^
glo.java:54: error: class, interface, or enum expected
    for (int i : all) {
    ^
glo.java:56: error: class, interface, or enum expected
        cur++;
        ^
glo.java:57: error: class, interface, or enum expected
    }
    ^
glo.java:60: error: class, interface, or enum expected
    vector<int> org(v.begin(), v.end());
    ^
glo.java:61: error: class, interface, or enum expected
    set<array<int, 2>> orgAndNew;
    ^
glo.java:62: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
    ^
glo.java:62: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
glo.java:62: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
glo.java:64: error: class, interface, or enum expected
        orgAndNew.insert({org[i], v[i]});
        ^
glo.java:65: error: class, interface, or enum expected
    }
    ^
glo.java:67: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
glo.java:67: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
glo.java:69: error: class, interface, or enum expected
        it--;
        ^
glo.java:70: error: class, interface, or enum expected
        getsTo[v[i]] = (*it)[1];
        ^
glo.java:71: error: class, interface, or enum expected
    }
    ^
glo.java:73: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
glo.java:73: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
glo.java:75: error: class, interface, or enum expected
        insertMax(v[i], 1 + getMax(0, v[i] - 1, 0, N - 1, 1, 0), 0, N - 1, 1, 0);
        ^
glo.java:76: error: class, interface, or enum expected
        insertMax(v[i], 1 + getMax(0, v[i] - 1, 0, N - 1, 1, 1), 0, N - 1, 1, 1);
        ^
glo.java:77: error: class, interface, or enum expected
    }
    ^
glo.java:80: error: class, interface, or enum expected
}
^
58 errors