萌新刚学OI!WA90求助QAQ!!!

P4097 【模板】李超线段树 / [HEOI2013] Segment

Light_Poet @ 2019-08-07 13:43:58

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define ls(x) x * 2
#define rs(x) x * 2 + 1 
#define inf 123456789000
#define eps 1e-18
#define double long double
int read() {
    char cc = getchar(); int cn = 0, flus = 1;
    while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }
    while(cc >= '0' && cc <= '9')  cn = cn * 10 + cc - '0', cc = getchar();
    return cn * flus;
}
const int mod2 = 1e9 ;
const int mod = 39989 ; 
int lastans, n, idnex ; 
struct Tr {
    int id ; 
    double y1, y2 ; 
    void init() {
        y1 = -inf, y2 = -inf ; 
    }
} tr[mod * 4] ;
struct node {
    int id, val ; 
};
int fread() {
    return ( read() + lastans - 1 ) % mod + 1;
}
int fread2() {
    return ( read() + lastans - 1 ) % mod2 + 1;
}

double get( int x1, int y1, int x2, int y2, int x ) {
    double k, b ; 
    if( x1 == x2 ) {
        return max( y1, y2 ) ;
    }
    else {
        k = 1.0 * ( y2 - y1 ) / ( x2 - x1 ) ;
        b = 1.0 * y1 - 1.0 * k * x1 ; 
        return 1.0 * ( k * x + b ) ; 
    }
}
void build( int x, int l, int r ) {
    if( l == r ) {
        tr[x].init() ; return ; 
    }
    int mid = ( l + r ) >> 1 ;
    build( ls(x), l, mid ), build( rs(x), mid + 1, r ) ; 
}
void Ins( int x, int l, int r, int x1, int y1, int x2, int y2, int id ) {
    if( r < x1 || l > x2 ) return ; 
    double Y1 = get( x1, y1, x2, y2, l ), Y2 = get( x1, y1, x2, y2, r ) ;
    if( x1 <= l && r <= x2 ) {
        if( Y1 < tr[x].y1 + eps && Y2 < tr[x].y2 + eps ) return ; 
        if( Y1 > tr[x].y1 - eps && Y2 > tr[x].y2 - eps ) {
            tr[x].id = id ;
            tr[x].y1 = Y1, tr[x].y2 = Y2; 

            return ; 
        }
    }
    if( l == r ) return ; 
    int mid = ( l + r ) >> 1 ; 
    Ins( ls(x), l, mid, x1, y1, x2, y2, id ),
    Ins( rs(x), mid + 1, r, x1, y1, x2, y2, id ) ;
}
Tr back( Tr x, Tr y ) {
    if( x.y1 == y.y1 ) return x.id < y.id ? x : y ; 
    return ( x.y1 > y.y1 ) ? x : y ; 
}
Tr query( int x, int l, int r, int w ) {
    if( l == r || !x ) return tr[x] ; 
    int mid = ( l + r ) >> 1 ; 
    Tr u = tr[x] ; u.y1 = get( l, tr[x].y1, r, tr[x].y2, w ) ;
    if( mid >= w ) return back( u, query( ls(x), l, mid, w ) ) ;
    else return back( u, query( rs(x), mid + 1, r, w ) ) ;
}
signed main()
{
    n = read() ; build( 1, 1, mod ) ;
    int opt, x1, x2, y1, y2;
    rep( i, 1, n ) {
        opt = read(), x1 = fread() ; 
        if( opt == 0 ) lastans = query( 1, 1, mod, x1 ).id, printf("%lld\n", lastans ) ;
        else {
            y1 = fread2(), x2 = fread(), y2 = fread2() ; 
            if( x1 > x2 ) swap( x1, x2 ), swap( y1, y2 ) ;
            ++ idnex, Ins( 1, 1, mod, x1, y1, x2, y2, idnex ) ;
        }
    }
    return 0;
}
Wrong Answer. wrong answer On line 42060 column 5, read 2, expected 3.

by YosemiteHe @ 2019-08-07 13:44:57

@Light_Poe 你这还刚学OI???


by pidan @ 2019-08-07 13:46:05

qndgxoi


by xyf007 @ 2019-08-07 13:49:31

刚学OI %%%


by zhy137036 @ 2019-08-07 14:01:38

刚学OI %%%


by MC方块人 @ 2019-08-07 14:09:49

刚学OI做省选,NB


by Light_Poet @ 2019-08-07 20:57:55

@pidan @xyf007 所以我WA了啊QAQ...


by Light_Poet @ 2019-08-12 13:49:51

问题已解决,get函数传的参数是int类型...nmdwsm


|