Cod sursa(job #2421562)

Utilizator rainerretzler rainer Data 15 mai 2019 11:38:14
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.47 kb
/// bril.cpp : Defines the entry point for the console application.

    //



    //#include "stdafx.h"

    //#include <fstream>

#include <cstdio>

#include <stdio.h>

    using namespace std;



#define min(a,b) (a>b?b:a)

#define max(a,b) (a<b?b:a)





//ifstream fin("arbint.in");

//ofstream fout("arbint.out");



FILE *fin, *fout;

















int noduri[270010];

int n, m,a,b;





void constr(int poz, int left, int right) {

    if (left == right) {

        //fin >> noduri[poz];

        //fscanf_s(fin, "%d", &noduri[poz]);

        fscanf(fin, "%d", &noduri[poz]);



        }

    else {

        int mid = (left + right) / 2;

        constr(2 * poz, left, mid);

        constr(2 * poz+1, mid+1, right);



        noduri[poz] = max(noduri[2 * poz], noduri[2 * poz + 1]);

        }

    }





void do1(int poz, int left, int right) {

    if (left == a&&right == a)

        noduri[poz] = b;

    else {

        int mid = (left + right) / 2;

        if (a <= mid)

            do1(2*poz, left, mid);

        else

            do1(2*poz+1, mid+1, right);

        noduri[poz] = max(noduri[2 * poz], noduri[2 * poz + 1]);

        }

    }



int do0(int poz, int a, int b, int left, int right) {

    if (left == a&&right == b)

        return noduri[poz];

    int mid = (left + right) / 2;

    if (b <= mid)

        return do0(2*poz, a, b, left, mid);

    if (a <= mid&&b > mid){
        int x1=do0(2 * poz, a, mid, left, mid), x2=do0(2 * poz + 1,mid+1,b, mid+1, right);
        return max(x1,x2);
        }

    if (a > mid)

        return do0(2 * poz+1, a, b, mid+1, right);

    return 0;



    }





int main()

    {



    //errno_t err;

    //err = fopen_s(&fin, "arbint.in", "r");

    //err = fopen_s(&fout, "arbint.out", "w");

    fin=fopen( "arbint.in", "r");

    fout=fopen("arbint.out", "w");

    //fin >> n >> m;

    fscanf(fin, "%d%d", &n,&m);

    //fscanf_s(fin, "%d%d", &n, &m);



    constr(1,1,n);

    int x, y, z;

    for (int i = 1; i <= m; ++i) {

        fscanf(fin, "%d%d%d", &x, &a,&b);

        //fscanf_s(fin, "%d%d%d", &x, &y, &z);

        if (x == 0)

            //fout << do0(1,y,z)<<"\n";

            fprintf(fout, "%d\n", do0(1,a,b,1,n));

        else

            do1(1,1,n);

        }

    fclose(fin);

    fclose(fout);

    return 0;

    }