답안 #637524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637524 2022-09-02T11:22:19 Z tvladm2009 Simple (info1cup19_simple) C++14
컴파일 오류
0 ms 0 KB
=#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int MAX_N = 2 * 1e5;
const ll INF = (1LL << 60);
 
int a[MAX_N + 1];
 
int n, q;
 
struct Node {
    ll maxEven;
    ll minEven;
    ll maxOdd;
    ll minOdd;
 
    Node() {
        maxEven = -1;
        minEven = INF;
        maxOdd = -1;
        minOdd = INF;
    }
};
 
Node aint[4 * MAX_N + 1];
ll lazy[4 * MAX_N + 1];
 
Node join(Node lson, Node rson) {
    Node aux;
    aux.maxEven = max(lson.maxEven, rson.maxEven);
    aux.minEven = min(lson.minEven, rson.minEven);
    aux.maxOdd = max(lson.maxOdd, rson.maxOdd);
    aux.minOdd = min(lson.minOdd, rson.minOdd);
    return aux;
}
 
void modify(Node &parent, ll val) {
    if (val & 1) {
        swap(parent.maxEven, parent.maxOdd);
        swap(parent.minEven, parent.minOdd);
    }
    if (parent.maxEven != -1) {
        parent.maxEven += val;
    }
    if (parent.minEven != INF) {
        parent.minEven += val;
    }
    if (parent.maxOdd != -1) {
        parent.maxOdd += val;
    }
    if (parent.minOdd != INF) {
        parent.minOdd += val;
    }
}
 
void push(int v) {
    if (lazy[v] != 0) {
        lazy[2 * v] += lazy[v];
        modify(aint[2 * v], lazy[v]);
        lazy[2 * v + 1] += lazy[v];
        modify(aint[2 * v + 1], lazy[v]);
        lazy[v] = 0;
    }
}
 
void build(int v, int l, int r) {
    if (l == r) {
        if (a[l] & 1) {
            aint[v].maxOdd = a[l];
            aint[v].minOdd = a[l];
        } else {
            aint[v].maxEven = a[l];
            aint[v].minEven = a[l];
        }
    } else {
        int mid = (l + r) / 2;
        build(2 * v, l, mid);
        build(2 * v + 1, mid + 1, r);
        aint[v] = join(aint[2 * v], aint[2 * v + 1]);
    }
}
 
void update(int v, int l, int r, int p, int q, int val) {
    if (p > q) {
        return;
    } else if (p <= l && r <= q) {
        modify(aint[v], val);
        lazy[v] += val;
    } else {
        push(v);
        int mid = (l + r) / 2;
        update(2 * v, l, mid, p, min(mid, q), val);
        update(2 * v + 1, mid + 1, r, max(p, mid + 1), q, val);
        aint[v] = join(aint[2 * v], aint[2 * v + 1]);
    }
}
 
Node tmp;
 
Node query(int v, int l, int r, int p, int q) {
    if (p > q) {
        return tmp;
    } else if (p <= l && r <= q) {
        return aint[v];
    } else {
        push(v);
        int mid = (l + r) / 2;
        Node ql = query(2 * v, l, mid, p, min(mid, q));
        Node qr = query(2 * v + 1, mid + 1, r, max(p, mid + 1), q);
        return join(ql, qr);
    }
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
 
    build(1, 1, n);
    cin >> q;
    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        if (t == 0) {
            int val;
            cin >> val;
            update(1, 1, n, l, r, val);
            for (int i = l; i <= r; i++) {
                a[i] += val;
            }
        } else {
            Node q = query(1, 1, n, l, r);
            if (q.minEven == INF) {
                cout << "-1 ";
            } else {
                cout << q.minEven << " ";
            }
            cout << q.maxOdd << "\n";
        }
    }
 
    return 0;
}

Compilation message

subway.cpp:1:2: error: stray '#' in program
    1 | =#include <bits/stdc++.h>
      |  ^
subway.cpp:1:1: error: expected unqualified-id before '=' token
    1 | =#include <bits/stdc++.h>
      | ^
subway.cpp: In function 'Node join(Node, Node)':
subway.cpp:34:19: error: 'max' was not declared in this scope
   34 |     aux.maxEven = max(lson.maxEven, rson.maxEven);
      |                   ^~~
subway.cpp:35:19: error: 'min' was not declared in this scope
   35 |     aux.minEven = min(lson.minEven, rson.minEven);
      |                   ^~~
subway.cpp: In function 'void modify(Node&, ll)':
subway.cpp:43:9: error: 'swap' was not declared in this scope
   43 |         swap(parent.maxEven, parent.maxOdd);
      |         ^~~~
subway.cpp: In function 'void update(int, int, int, int, int, int)':
subway.cpp:96:34: error: 'min' was not declared in this scope; did you mean 'mid'?
   96 |         update(2 * v, l, mid, p, min(mid, q), val);
      |                                  ^~~
      |                                  mid
subway.cpp:97:39: error: 'max' was not declared in this scope
   97 |         update(2 * v + 1, mid + 1, r, max(p, mid + 1), q, val);
      |                                       ^~~
subway.cpp: In function 'Node query(int, int, int, int, int)':
subway.cpp:112:43: error: 'min' was not declared in this scope; did you mean 'mid'?
  112 |         Node ql = query(2 * v, l, mid, p, min(mid, q));
      |                                           ^~~
      |                                           mid
subway.cpp:113:48: error: 'max' was not declared in this scope
  113 |         Node qr = query(2 * v + 1, mid + 1, r, max(p, mid + 1), q);
      |                                                ^~~
subway.cpp: In function 'int main()':
subway.cpp:119:5: error: 'ios_base' has not been declared
  119 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
subway.cpp:120:5: error: 'cin' was not declared in this scope
  120 |     cin.tie(0);
      |     ^~~
subway.cpp:121:5: error: 'cout' was not declared in this scope
  121 |     cout.tie(0);
      |     ^~~~