Cod sursa(job #3298256)

Utilizator RobertMM05Molcomis Robert-Marian RobertMM05 Data 28 mai 2025 16:57:41
Problema Arbori de intervale Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 1.73 kb
#include <stdio.h>
#include <string.h>

#define lenght 100001

/*
int powlg(int x, int p, int MOD) {
    int val = 1;
    while (p) {
        if (p & 1)
            val = 1LL * val * x %MOD;
        x = 1LL * x * x % MOD;
        p >>= 1;
    }
    return val;
}
*/

int n, m, a[4 * lenght + 66];
int val, pos, max, start, end;

int maximum(int x, int y) {
    return x > y ? x : y;
}

void actualize(int nod, int st, int dr) {
    if(st == dr) {
        a[nod] = val;
        return;
    }

    int mij = (st + dr) / 2;
    if(pos <= mij) {
        actualize(2 * nod, st, mij);
    } else {
        actualize(2 * nod + 1, mij + 1, dr);
    }

    a[nod] = maximum(a[2 * nod], a[2 * nod + 1]);
}

void query(int nod, int st, int dr) {
    if(start <= st && dr <= end) {
        max = maximum(max, a[nod]);
        return;
    }

    int mij = (st + dr) / 2;
    if(start <= mij) {
        query(2 * nod, st, mij);
    }
    if(mij < end) {
        query(2 * nod + 1, mij + 1, dr);
    }
}


int main() {
    FILE *input = fopen("arbint.in", "r");
    FILE *output = fopen("arbint.out", "w");

    int x, y, z;

    fscanf(input, "%d %d", &n, &m);
    for(int i = 1; i <= n; i++) {
        fscanf(input, "%d", &x);
        pos = i;
        val = x;
        actualize(1, 1, n);
    }

    for(int i = 1; i <= m; i++) {
        fscanf(input, "%d %d %d", &x, &y, &z);
        if (!x) {
            max = -1;
            start = y;
            end = z;
            query(1, 1, n);
            fprintf(output, "%d\n", max);
        } else {
            pos = y;
            val = z;
            actualize(1, 1, n);
        }
    }

    fclose(input);
    fclose(output);

    return 0;
}