Submission #411402

#TimeUsernameProblemLanguageResultExecution timeMemory
411402jhwest2Wall (IOI14_wall)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long lint;
typedef pair<int, int> pint;
const int M = 2e6 + 10;
const int INF = 1e9 + 10;

int n, k, A[M];

struct SEG {
    int T[M << 2][2], L[M << 2][2];

    void init(int lo = 1, int hi = n, int idx = 1) {
        L[idx][0] = L[idx][1] = INF;
        if (lo == hi) return;
        init(lo, lo + hi >> 1, idx << 1);
        init(1 + (lo + hi >> 1), hi, idx << 1 | 1);
    }
    void push(int lo, int hi, int idx) {
        for (int j = 0; j < 2; j++) {
            int x = L[idx][j];
            if (x == INF) continue;
            if (x > 0) T[idx][j] = max(T[idx][j], x);
            else T[idx][j] = min(T[idx][j], -x);

            if (lo != hi) {
                for (int i = idx << 1; i <= (idx << 1 | 1); i++) {
                    if (L[i][j] == INF) L[i][j] = x;
                    else if (x > 0 && L[i][j] <= 0 && -L[i][j] < x) {
                        if (T[i][j] >= x) L[i][j] = -x;
                        else L[i][j] = x;
                    }
                    else if (x <= 0 && L[i][j] > 0 && -x < L[i][j]) {
                        if (T[i][j] <= -x) L[i][j] = -x;
                        else L[i][j] = x;    
                    }
                    else L[i][j] = max(L[i][j], x);
                }
            }
            L[idx][j] = INF;
        }
    }
    void update(int a, int b, int x, int lo = 1, int hi = n, int idx = 1) {
        push(lo, hi, idx);
        if (b < lo || a > hi) return;
        if (a <= lo && hi <= b) {
            L[idx][0] = L[idx][1] = x; push(lo, hi, idx); return;
        }
        update(a, b, x, lo, lo + hi >> 1, idx << 1);
        update(a, b, x, 1 + (lo + hi >> 1), hi, idx << 1 | 1);
        T[idx][0] = min(T[idx << 1][0], T[idx << 1 | 1][0]);
        T[idx][1] = max(T[idx << 1][1], T[idx << 1 | 1][1]);
    }
    int query(int a, int lo = 1, int hi = n, int idx = 1) {
        push(lo, hi, idx);
        if (lo == hi) return T[idx][0];
        if (a <= lo + hi >> 1) return query(a, lo, lo + hi >> 1, idx << 1);
        else return query(a, 1 + (lo + hi >> 1), hi, idx << 1 | 1);
    }
} S;
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> k; S.init();
    for (int i = 1; i <= k; i++) {
        int op, l, r, h;
        cin >> op >> l >> r >> h; ++l; ++r;
        if (op == 1 && h != 0) S.update(l, r, h);
        if (op == 2) S.update(l, r, -h);
    }
    for (int i = 1; i <= n; i++) {
        cout << S.query(i) << '\n';
    }
}

Compilation message (stderr)

wall.cpp: In member function 'void SEG::init(int, int, int)':
wall.cpp:18:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |         init(lo, lo + hi >> 1, idx << 1);
      |                  ~~~^~~~
wall.cpp:19:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |         init(1 + (lo + hi >> 1), hi, idx << 1 | 1);
      |                   ~~~^~~~
wall.cpp: In member function 'void SEG::update(int, int, int, int, int, int)':
wall.cpp:51:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         update(a, b, x, lo, lo + hi >> 1, idx << 1);
      |                             ~~~^~~~
wall.cpp:52:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |         update(a, b, x, 1 + (lo + hi >> 1), hi, idx << 1 | 1);
      |                              ~~~^~~~
wall.cpp: In member function 'int SEG::query(int, int, int, int)':
wall.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         if (a <= lo + hi >> 1) return query(a, lo, lo + hi >> 1, idx << 1);
      |                  ~~~^~~~
wall.cpp:59:55: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         if (a <= lo + hi >> 1) return query(a, lo, lo + hi >> 1, idx << 1);
      |                                                    ~~~^~~~
wall.cpp:60:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         else return query(a, 1 + (lo + hi >> 1), hi, idx << 1 | 1);
      |                                   ~~~^~~~
/usr/bin/ld: /tmp/ccNIu9K0.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXlRrr1.o:wall.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccNIu9K0.o: in function `main':
grader.cpp:(.text.startup+0x133): undefined reference to `buildWall(int, int, int*, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status