Cod sursa(job #475693)

Utilizator SpiderManSimoiu Robert SpiderMan Data 8 august 2010 01:17:34
Problema Marbles Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
# include <algorithm>
using namespace std;

# define x first
# define y second

const char FIN[] = "marbles.in", FOU[] = "marbles.out" ;
const int MAX = 100005 ;

int N, M;

pair < int, int > V[MAX] ;

int S[MAX][65];

int main() {
    freopen ( FIN, "r", stdin ) ;
    freopen ( FOU, "w", stdout ) ;

    scanf ( "%d %d", &N, &M ) ;

    for ( int i = 1; i <= N; ++i ) {
        scanf ( "%d %d", &V[i].x, &V[i].y ) ;
    }

    sort ( V + 1, V + N + 1 ) ;

    for ( int i = 1; i <= N; ++i ) {
        for ( int j = 1; j <= 1 << 6; ++j ) {
            S[ i ][ j ] += S[i - 1][ j ] ;
        }
        ++S[ i ][ V[ i ].y ] ;
    }

    int aux = 0;

    for ( aux = 1; aux << 1 <= N; aux <<= 1 ) ;

    for ( int i = 1, a, b, c; i <= M; ++i ) {
        scanf ( "%d %d %d", &c, &a, &b ) ;

        if ( c ) {
            int f1, f2, cnt, sol = 0 ;

            for ( f1 = 0, cnt = aux; cnt; cnt >>= 1 ) {
                if ( f1 + cnt <= N && V[f1 + cnt].x < a ) {
                    f1 += cnt ;
                }
            }

            for ( f2 = 0, cnt = aux; cnt; cnt >>= 1 ) {
                if ( f2 + cnt <= N && V[f2 + cnt].x <= b ) {
                    f2 += cnt ;
                }
            }

            for ( int j = 1; j <= 1 << 6; ++j ) {
                if ( S[f2][j] - S[f1][j] > sol ) {
                    sol = S[f2][j] - S[f1][j] ;
                }
            }

            printf ( "%d\n", sol ) ;

        } else {
            int f1, f2, cnt ;
            for ( f1 = 0, cnt = aux; cnt; cnt >>= 1 ) {
                if ( f1 + cnt <= N && V[f1 + cnt].x <= a ) {
                    f1 += cnt ;
                }
            }

            V[f1].x += b ;
        }
    }

    return 0;
}