QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#161140#7108. Couleurucup-team197#AC ✓3930ms66980kbC++144.4kb2023-09-02 22:36:052023-09-02 22:36:06

Judging History

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

  • [2023-09-02 22:36:06]
  • 评测
  • 测评结果:AC
  • 用时:3930ms
  • 内存:66980kb
  • [2023-09-02 22:36:05]
  • 提交

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 ;
#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 ;

int n ;
int a[ MAXN ] ;
struct node {
    int cnt ;
    int pl , pr ;
    node ( ) { cnt = pl = pr = 0 ; }
};

int tp ;
node tr[ 40 * MAXN ] ;

int root[ MAXN ] ;

int init ( int l , int r ) {
    int ret = ++ tp ;
    if ( l == r ) { return ret ; }
    int mid = ( l + r ) / 2 ;
    tr[ ret ].pl = init ( l , mid ) ;
    tr[ ret ].pr = init ( mid + 1 , r ) ;
    return ret ;
}

int update ( int w , int l , int r , int pos ) {
    int ret = ++ tp ;
    tr[ ret ].cnt = tr[ w ].cnt + 1 ; tr[ ret ].pl = tr[ w ].pl , tr[ ret ].pr = tr[ w ].pr ; 
    if ( l == r ) {
        return ret ;
    }
    int mid = ( l + r ) / 2 ;
    if ( pos <= mid ) { tr[ ret ].pl = update ( tr[ w ].pl , l , mid , pos ) ; }
    else { tr[ ret ].pr = update ( tr[ w ].pr , mid + 1 , r , pos ) ; }
    return ret ;
}

int query ( int w , int l , int r , int st , int en ) {
    if ( l > r || st > en ) { return 0 ; }
    if ( r < st || en < l ) { return 0 ; }
    if ( st <= l && r <= en ) { return tr[ w ].cnt ; }
    int mid = ( l + r ) / 2 ;
    return query ( tr[ w ].pl , l , mid , st , en ) + query ( tr[ w ].pr , mid + 1 , r , st , en ) ;
}

set < int > s ;
multiset < ll > all_vals ;
map < pii , ll > w ;

void solve ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
    }
    tp = 0 ;
    root[ 0 ] = init ( 1 , n ) ;
    ll lstans = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        root[ i ] = update ( root[ i - 1 ] , 1 , n , a[ i ] ) ;
        lstans += query ( root[ i - 1 ] , 1 , n , a[ i ] + 1 , n ) ;
    }
    s.clear ( ) ;
    s.insert ( 0 ) ;
    s.insert ( n + 1 ) ;
    w.clear ( ) ;
    all_vals.clear ( ) ;
    w[ { 0 , n + 1 } ] = lstans ;
    all_vals.insert ( lstans ) ;
    cout << lstans << " " ;

    for ( int i = 1 ; i <= n ; ++ i ) {
        ll x ; cin >> x ;
        x ^= lstans ;
        if ( i == n ) { break ; }
        auto it1 = s.upper_bound ( x ) ;
        auto it2 = s.upper_bound ( x ) ;
        -- it2 ;
        int prv = *it2 , nxt = *it1 ;
        s.insert ( x ) ;
        ll l_side , r_side ;
        ll tot = w[ { prv , nxt } ] ;
        w.erase ( { prv , nxt } ) ;
        auto foo = all_vals.find ( tot ) ;
        all_vals.erase ( foo ) ;

        ll aux = 0 ;
        if ( x - prv < nxt - x ) {
            for ( int i = prv + 1 ; i <= x ; ++ i ) {
                if ( i < x ) { 
                    aux += query ( root[ i - 1 ] , 1 , n , a[ i ] + 1 , n ) - query ( root[ prv ] , 1 , n , a[ i ] + 1 , n ) ;
                }
                else {
                    tot -= query ( root[ i - 1 ] , 1 , n , a[ i ] + 1 , n ) - query ( root[ prv ] , 1 , n , a[ i ] + 1 , n ) ;
                }
                tot -= query ( root[ nxt - 1 ] , 1 , n , 1 , a[ i ] - 1 ) - query ( root[ x ] , 1 , n , 1 , a[ i ] - 1 ) ;
            }
            tot -= aux ;
            w[ { prv , x } ] = aux ;
            w[ { x , nxt } ] = tot ;
            all_vals.insert ( aux ) ;
            all_vals.insert ( tot ) ;
        }
        else {
            for ( int i = x ; i < nxt ; ++ i ) {
                if ( i > x ) {
                    aux += query ( root[ i - 1 ] , 1 , n , a[ i ] + 1 , n ) - query ( root[ x ] , 1 , n , a[ i ] + 1 , n ) ;
                }
                else {
                    tot -= query ( root[ nxt - 1 ] , 1 , n , 1 , a[ i ] - 1 ) - query ( root[ x ] , 1 , n , 1 , a[ i ] - 1 ) ;
                }
                tot -= query ( root[ x - 1 ] , 1 , n , a[ i ] + 1 , n ) - query ( root[ prv ] , 1 , n , a[ i ] + 1 , n ) ;
            }
            tot -= aux ;
            w[ { prv , x } ] = tot ;
            w[ { x , nxt } ] = aux ;
            all_vals.insert ( aux ) ;
            all_vals.insert ( tot ) ;
        }
        lstans = *all_vals.rbegin ( ) ;
        cout << lstans << " " ;
    }
    cout << "\n" ;
    for ( int i = 0 ; i <= tp ; ++ i ) {
        tr[ i ] = node ( ) ;
    }
}

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


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 50576kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3930ms
memory: 66980kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed