예제 #1
0
int read_data( FILE *fp,char *string_vars,int *int_vars,
               float *fl_vars, int **arraysi,float **arraysf,
               float *xmin,float *xmax, float *ymin,float *ymax,
               int *current, int req,int *maxrec,int rotate )
#endif
{
    int i,err=0,read=0,rec_num=0,rotate_velocity=1;
    long curr_pos;
    struct stat buf;

    curr_pos = ftell( fp );

    if (*current>req) {
        rewind( fp );
        *current=0;
    }
    rec_num = *current;
    while (rec_num<req-1) {
        if (err=skip_data_blk( fp )) {
            if (err==EOF_ERR) *maxrec = rec_num;
            return( err );
        }
        else rec_num++;
    }
    if (err=read_data_blk( fp,string_vars, int_vars,fl_vars,arraysi,arraysf)) {
        if (err==READ_ERR) {
            clear_arrays();
            rewind( fp );
            *current=0;
        }
        else if (err==EOF_ERR) {
            *maxrec = rec_num;
            fseek( fp,curr_pos,SEEK_SET );
        }
        return( err );
    }
    /*if (req==1) {*/
    if (*maxrec==0) {
        curr_pos = ftell( fp );
        err = fstat(fileno(fp),&buf);
        *maxrec = buf.st_size/curr_pos;
    }
    *current = req;
    if (rotate) {
         swapco_(arraysf[EX],arraysf[EY],arraysf[UVP],
                                &int_vars[NUP],&rotate,&rotate_velocity );
         if (int_vars[ILAG]) {
              rotate_velocity = 0;
              if (int_vars[ILAG]==1||int_vars[ILAG]==3)
                  swapco_(arraysf[EXLG],arraysf[EYLG],NULL,
                                &int_vars[NUL],&rotate,&rotate_velocity );
              i = int_vars[NSM] * int_vars[NPM];
              if (int_vars[ILAG]==1||int_vars[ILAG]==2)
                  swapco_(arraysf[STELPX],arraysf[STELPY],NULL,
                                &i,&rotate,&rotate_velocity );
         }
    }
    find_max_min(arraysf[EX],arraysf[EY],int_vars[NUP],xmin,xmax,ymin,ymax);
    return( 0 );
}
int main()
{
    int i, q, a, b, h, M;
    Node nd;
    scanf("%d %d", &n, &q);
    for (i = 1; i <= n; i++) {
        scanf("%d", &h);
        f[i][0].Max = f[i][0].Min = h;
    }
    build_tree();
    for (i = 0; i < q; i++) {
        scanf("%d %d", &a, &b);
        nd = find_max_min(a, b);
        printf("%d\n", nd.Max - nd.Min);
    }
    return 0;
}