QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143277#7020. The Kouga Ninja ScrollsSorting#AC ✓997ms58612kbC++204.9kb2023-08-21 00:37:372023-08-21 00:38:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-21 00:38:49]
  • 评测
  • 测评结果:AC
  • 用时:997ms
  • 内存:58612kb
  • [2023-08-21 00:37:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ; 
typedef vector<int> vi;
typedef vector < long long > vl ;
typedef unsigned int uint ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 1e5 + 7 ;
const ll inf = 1e18 ;
int n , q ;
pair < ll , ll > a[ MAXN ] ;
int cl[ MAXN ] ;

struct node {
    ll ans ;
    pair < ll , int > mx[ 2 ][ 2 ][ 2 ] ; // cx , cy , wh
    node ( ) {
        ans = 0 ;
        for ( int i = 0 ; i < 2 ; ++ i ) {
            for ( int j = 0 ; j < 2 ; ++ j ) {
                for ( int t = 0 ; t < 2 ; ++ t ) {
                    mx[ i ][ j ][ t ] = { -inf , 0 } ;
                }
            }
        }
    }
};

node unite ( node p1 , node p2 ) {
    node ret = node ( ) ;
    ret.ans = max ( p1.ans , p2.ans ) ;
    for ( int i = 0 ; i < 2 ; ++ i ) {
        for ( int j = 0 ; j < 2 ; ++ j ) {
            for ( int t = 0 ; t < 2 ; ++ t ) {
                for ( int z = 0 ; z < 2 ; z ++ ) {
                    if ( p1.mx[ i ][ j ][ t ].se == p2.mx[ z ][ j ^ 1 ][ t ^ 1 ].se ) { continue ; }
                    ret.ans = max ( ret.ans , p1.mx[ i ][ j ][ t ].fi + p2.mx[ z ][ j ^ 1 ][ t ^ 1 ].fi ) ;
                }
            }
        }
    }
    for ( int j = 0 ; j < 2 ; ++ j ) {
        for ( int t = 0 ; t < 2 ; ++ t ) {
            ret.mx[ 0 ][ j ][ t ] = max ( p1.mx[ 0 ][ j ][ t ] , p2.mx[ 0 ][ j ][ t ] ) ;
            int sr = ret.mx[ 0 ][ j ][ t ].se ;
            if ( p1.mx[ 0 ][ j ][ t ].se != sr ) {
                ret.mx[ 1 ][ j ][ t ] = max ( ret.mx[ 1 ][ j ][ t ] , p1.mx[ 0 ][ j ][ t ] ) ;
            }
            if ( p1.mx[ 1 ][ j ][ t ].se != sr ) {
                ret.mx[ 1 ][ j ][ t ] = max ( ret.mx[ 1 ][ j ][ t ] , p1.mx[ 1 ][ j ][ t ] ) ;
            }
            if ( p2.mx[ 0 ][ j ][ t ].se != sr ) {
                ret.mx[ 1 ][ j ][ t ] = max ( ret.mx[ 1 ][ j ][ t ] , p2.mx[ 0 ][ j ][ t ] ) ;
            }
            if ( p2.mx[ 1 ][ j ][ t ].se != sr ) {
                ret.mx[ 1 ][ j ][ t ] = max ( ret.mx[ 1 ][ j ][ t ] , p2.mx[ 1 ][ j ][ t ] ) ;
            }
        }
    }
    return ret ;
};

class Tree {
public :
    node tr[ 4 * MAXN ] ;
    void set_pos ( int w , int l ) {
        tr[ w ].ans = 0 ;
        for ( int i = 0 ; i < 2 ; ++ i ) {
            for ( int j = 0 ; j < 2 ; ++ j ) {
                ll sm = 0 ;
                if ( i == 0 ) { sm -= a[ l ].fi ; }
                else { sm += a[ l ].fi ; }
                if ( j == 0 ) { sm -= a[ l ].se ; }
                else { sm += a[ l ].se ; }
                tr[ w ].mx[ 0 ][ i ][ j ] = { sm , cl[ l ] } ;
                tr[ w ].mx[ 1 ][ i ][ j ] = { -inf , 0 } ;
            }
        }
    }
    void init ( int w , int l , int r ) {
        if ( l == r ) {
            set_pos ( w , l ) ;
            return ;
        }
        int mid = ( l + r ) / 2 ;
        init ( 2 * w , l , mid ) ;
        init ( 2 * w + 1 , mid + 1 , r ) ;
        tr[ w ] = unite ( tr[ 2 * w ] , tr[ 2 * w + 1 ] ) ;
    }
    void update ( int w , int l , int r , int pos ) {
        if ( l == r ) {
            set_pos ( w , l ) ;
            return ;
        }
        int mid = ( l + r ) / 2 ;
        if ( pos <= mid ) { update ( 2 * w , l , mid , pos ) ; } 
        else { update ( 2 * w + 1 , mid + 1 , r , pos ) ; }
        tr[ w ] = unite ( tr[ 2 * w ] , tr[ 2 * w + 1 ] ) ;
    }
    node query ( int w , int l , int r , int st , int en ) {
        if ( l > r || st > en ) { return node ( ) ; }
        if ( r < st || en < l ) { return node ( ) ; }
        if ( st <= l && r <= en ) { return tr[ w ] ; }
        int mid = ( l + r ) / 2 ;
        return unite ( query ( 2 * w , l , mid , st , en ) , query ( 2 * w + 1 , mid + 1 , r , st , en ) ) ;
    }
};
Tree w ;

int test_id ;

void solve ( ) {
    ++ test_id ;
    cout << "Case #" << test_id << ":\n" ;
    cin >> n >> q ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ].fi >> a[ i ].se >> cl[ i ] ;
    }
    w.init ( 1 , 1 , n ) ;
    while ( q -- ) {
        int type ; cin >> type ;
        if ( type == 1 ) {
            int k , x , y ;
            cin >> k >> x >> y ;
            a[ k ].fi += x , a[ k ].se += y ;
            w.update ( 1 , 1 , n , k ) ;
        }
        else if ( type == 2 ) {
            int k , nw ;
            cin >> k >> nw ;
            cl[ k ] = nw ;
            w.update ( 1 , 1 , n , k ) ;
        }
        else {
            int l , r ;
            cin >> l >> r ;
            node ret = w.query ( 1 , 1 , n , l , r ) ;
            cout << ret.ans << "\n" ;
        }
    }
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}


这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 11ms
memory: 57168kb

input:

1
2 8
0 0 1
1 1 2
3 1 2
1 1 1 1
3 1 2
1 1 1 1
2 1 2
3 1 2
2 1 1
3 1 2

output:

Case #1:
2
0
0
2

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 997ms
memory: 58612kb

input:

60
500 500
869676911 -813404481 62
-945322435 46069424 18
-178313683 -431754291 62
365370429 989841420 403
581432447 750507267 482
151389216 29933356 18
-526811063 -170809743 105
862783905 920464530 91
343253321 -871223893 192
403379791 828503986 91
775506325 -370049275 192
533550283 -577541037 482
...

output:

Case #1:
3685787673
3468859321
3333691523
3468859321
3333691523
3333691523
3961865677
4160346448
3515366597
4160346448
3751993658
4096942446
4554140217
4554140217
2383169926
3685167062
3617781469
4554140217
3173729474
4625859024
3707466685
4554140217
4753589768
3960896897
4554140217
4554140217
45541...

result:

ok 216379 lines