bzoj 1067 分情况讨论
这道题考察人的严谨,各种情况分类讨论。
1 #include <cstdio> 2 #include <algorithm> 3 #include <map> 4 #define maxn 50010 5 #define maxq 17 6 #define P(i) (1<<(i)) 7 #define yes 0 8 #define no 1 9 #define maybe 2 10 using namespace std; 11 12 int n, q; 13 int year[maxn]; 14 int st[maxn][maxq]; 15 16 int ind( int y ) { 17 return (lower_bound( year+1, year+n+1, y ) - year); 18 } 19 void makest() { 20 for( int q=1; q<maxq; q++ ) 21 for( int i=1; i<=(n-P(q)+1); i++ ) 22 st[i][q] = max( st[i][q-1], st[i+P(q-1)][q-1] ); 23 } 24 int fmax( int lf, int rg ) { 25 int len = rg-lf+1; 26 if( len<=0 ) return -1; 27 for( int q=maxq-1; q>=0; q-- ) 28 if( len>P(q) ) { 29 return max( st[lf][q], st[rg-P(q)+1][q] ); 30 } else if( len==P(q) ) { 31 return st[lf][q]; 32 } 33 return -1; 34 } 35 int main() { 36 scanf( "%d", &n ); 37 year[n+1] = 0x7FFFFFFF; 38 for( int i=1; i<=n; i++ ) 39 scanf( "%d%d", year+i, &st[i][0] ); 40 makest(); 41 sort( year+1, year+1+n ); 42 scanf( "%d", &q ); 43 while( q-- ) { 44 int a, b, ia, ib; 45 scanf( "%d%d", &a, &b ); 46 ia = ind(a), ib = ind(b); 47 if( year[ia]==a && year[ib]==b && b-a==ib-ia && st[ia][0]>=st[ib][0] && fmax(ia+1,ib-1)<st[ib][0] ) { 48 printf( "true\n" ); 49 continue; 50 } 51 if( year[ia]==a && year[ib]==b && b-a>ib-ia && st[ia][0]>=st[ib][0] && fmax(ia+(year[ia]==a),ib-1)<st[ib][0] ) { 52 printf( "maybe\n" ); 53 continue; 54 } 55 if( ((year[ia]==a)^(year[ib]==b)) && fmax(ia+(year[ia]==a),ib-1)< (year[ia]==a ? st[ia][0] : st[ib][0]) ) { 56 printf( "maybe\n" ); 57 continue; 58 } 59 if( year[ia]!=a && year[ib]!=b ) { 60 printf( "maybe\n" ); 61 continue; 62 } 63 printf( "false\n" ); 64 } 65 }