Submission #37146

# Submission time Handle Problem Language Result Execution time Memory
37146 2017-12-21T15:54:55 Z chonka Money (IZhO17_money) C++
100 / 100
916 ms 33272 KB
#include<iostream>
#include<stdio.h>
using namespace std ;

#define MAXN 1000007

int n ;
int a[ MAXN ] ;

int nxt[ MAXN ] ;
int prv[ MAXN ] ;

class Tree {
    public :
    int tr[ 5 * MAXN ] ;
    void init ( int where , int IL , int IR ) {
        tr[ where ] = 0 ;
        if ( IL == IR ) { return ; }
        int mid = ( IL + IR ) / 2 ;
        init ( 2 * where , IL , mid ) ;
        init ( 2 * where + 1 , mid + 1 , IR ) ;
    }
    void update ( int where , int IL , int IR , int pos , int val ) {
        if ( IR < pos || pos < IL ) { return ; }
        if ( IL == IR ) { tr[ where ] += val ; return ; }
        int mid = ( IL + IR ) / 2 ;
        if ( pos <= mid ) {
            update ( 2 * where , IL , mid , pos , val ) ;
        }
        else {
            update ( 2 * where + 1 , mid + 1 , IR , pos , val ) ;
        }
        tr[ where ] = tr[ 2 * where ] + tr[ 2 * where + 1 ] ;
    }
    int query ( int where , int IL , int IR , int CURL , int CURR ) {
        if ( CURL > CURR ) { return 0 ; }
        if ( IR < CURL || CURR < IL ) { return 0 ; }
        if ( CURL <= IL && IR <= CURR ) { return tr[ where ] ; }
        int mid = ( IL + IR ) / 2 ;
        return ( query ( 2 * where , IL , mid , CURL , CURR ) + query ( 2 * where + 1 , mid + 1 , IR , CURL , CURR ) ) ;
    }
};

Tree w ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
    int lim = 1000000 ;
    w.init ( 1 , 1 , lim ) ;
    int i ;
    int ans = 0 ;
    for ( i = 1 ; i <= n ; i ++ ) {
        int j ;
        int mn , mx ;
        mx = mn = a[ i ] ;
        for ( j = i ; j <= n ; j ++ ) {
            if ( i != j && a[ j ] < a[ j - 1 ] ) { break ; }
            if ( mn > a[ j ] ) { mn = a[ j ] ; }
            if ( mx < a[ j ] ) { mx = a[ j ] ; }
            if ( w.query ( 1 , 1 , lim , mn + 1 , mx - 1 ) != 0 ) { break ; }
        }
        ans ++ ;
        for ( int t = i ; t < j ; t ++ ) {
            w.update ( 1 , 1 , lim , a[ t ] , 1 ) ;
        }
        i = j - 1 ;
    }
    printf ( "%d\n" , ans ) ;
}

int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

Compilation message

money.cpp: In function 'void input()':
money.cpp:47:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &n ) ;
                         ^
money.cpp:50:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 33272 KB Output is correct
2 Correct 3 ms 33272 KB Output is correct
3 Correct 6 ms 33272 KB Output is correct
4 Correct 0 ms 33272 KB Output is correct
5 Correct 6 ms 33272 KB Output is correct
6 Correct 6 ms 33272 KB Output is correct
7 Correct 3 ms 33272 KB Output is correct
8 Correct 3 ms 33272 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 9 ms 33272 KB Output is correct
11 Correct 6 ms 33272 KB Output is correct
12 Correct 6 ms 33272 KB Output is correct
13 Correct 3 ms 33272 KB Output is correct
14 Correct 6 ms 33272 KB Output is correct
15 Correct 3 ms 33272 KB Output is correct
16 Correct 6 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 33272 KB Output is correct
2 Correct 3 ms 33272 KB Output is correct
3 Correct 6 ms 33272 KB Output is correct
4 Correct 0 ms 33272 KB Output is correct
5 Correct 6 ms 33272 KB Output is correct
6 Correct 6 ms 33272 KB Output is correct
7 Correct 3 ms 33272 KB Output is correct
8 Correct 3 ms 33272 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 9 ms 33272 KB Output is correct
11 Correct 6 ms 33272 KB Output is correct
12 Correct 6 ms 33272 KB Output is correct
13 Correct 3 ms 33272 KB Output is correct
14 Correct 6 ms 33272 KB Output is correct
15 Correct 3 ms 33272 KB Output is correct
16 Correct 6 ms 33272 KB Output is correct
17 Correct 6 ms 33272 KB Output is correct
18 Correct 9 ms 33272 KB Output is correct
19 Correct 9 ms 33272 KB Output is correct
20 Correct 3 ms 33272 KB Output is correct
21 Correct 6 ms 33272 KB Output is correct
22 Correct 6 ms 33272 KB Output is correct
23 Correct 9 ms 33272 KB Output is correct
24 Correct 6 ms 33272 KB Output is correct
25 Correct 6 ms 33272 KB Output is correct
26 Correct 3 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 33272 KB Output is correct
2 Correct 3 ms 33272 KB Output is correct
3 Correct 6 ms 33272 KB Output is correct
4 Correct 0 ms 33272 KB Output is correct
5 Correct 6 ms 33272 KB Output is correct
6 Correct 6 ms 33272 KB Output is correct
7 Correct 3 ms 33272 KB Output is correct
8 Correct 3 ms 33272 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 9 ms 33272 KB Output is correct
11 Correct 6 ms 33272 KB Output is correct
12 Correct 6 ms 33272 KB Output is correct
13 Correct 3 ms 33272 KB Output is correct
14 Correct 6 ms 33272 KB Output is correct
15 Correct 3 ms 33272 KB Output is correct
16 Correct 6 ms 33272 KB Output is correct
17 Correct 6 ms 33272 KB Output is correct
18 Correct 9 ms 33272 KB Output is correct
19 Correct 9 ms 33272 KB Output is correct
20 Correct 3 ms 33272 KB Output is correct
21 Correct 6 ms 33272 KB Output is correct
22 Correct 6 ms 33272 KB Output is correct
23 Correct 9 ms 33272 KB Output is correct
24 Correct 6 ms 33272 KB Output is correct
25 Correct 6 ms 33272 KB Output is correct
26 Correct 3 ms 33272 KB Output is correct
27 Correct 3 ms 33272 KB Output is correct
28 Correct 9 ms 33272 KB Output is correct
29 Correct 6 ms 33272 KB Output is correct
30 Correct 6 ms 33272 KB Output is correct
31 Correct 0 ms 33272 KB Output is correct
32 Correct 6 ms 33272 KB Output is correct
33 Correct 6 ms 33272 KB Output is correct
34 Correct 3 ms 33272 KB Output is correct
35 Correct 6 ms 33272 KB Output is correct
36 Correct 3 ms 33272 KB Output is correct
37 Correct 3 ms 33272 KB Output is correct
38 Correct 3 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 33272 KB Output is correct
2 Correct 3 ms 33272 KB Output is correct
3 Correct 6 ms 33272 KB Output is correct
4 Correct 0 ms 33272 KB Output is correct
5 Correct 6 ms 33272 KB Output is correct
6 Correct 6 ms 33272 KB Output is correct
7 Correct 3 ms 33272 KB Output is correct
8 Correct 3 ms 33272 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 9 ms 33272 KB Output is correct
11 Correct 6 ms 33272 KB Output is correct
12 Correct 6 ms 33272 KB Output is correct
13 Correct 3 ms 33272 KB Output is correct
14 Correct 6 ms 33272 KB Output is correct
15 Correct 3 ms 33272 KB Output is correct
16 Correct 6 ms 33272 KB Output is correct
17 Correct 6 ms 33272 KB Output is correct
18 Correct 9 ms 33272 KB Output is correct
19 Correct 9 ms 33272 KB Output is correct
20 Correct 3 ms 33272 KB Output is correct
21 Correct 6 ms 33272 KB Output is correct
22 Correct 6 ms 33272 KB Output is correct
23 Correct 9 ms 33272 KB Output is correct
24 Correct 6 ms 33272 KB Output is correct
25 Correct 6 ms 33272 KB Output is correct
26 Correct 3 ms 33272 KB Output is correct
27 Correct 3 ms 33272 KB Output is correct
28 Correct 9 ms 33272 KB Output is correct
29 Correct 6 ms 33272 KB Output is correct
30 Correct 6 ms 33272 KB Output is correct
31 Correct 0 ms 33272 KB Output is correct
32 Correct 6 ms 33272 KB Output is correct
33 Correct 6 ms 33272 KB Output is correct
34 Correct 3 ms 33272 KB Output is correct
35 Correct 6 ms 33272 KB Output is correct
36 Correct 3 ms 33272 KB Output is correct
37 Correct 3 ms 33272 KB Output is correct
38 Correct 3 ms 33272 KB Output is correct
39 Correct 159 ms 33272 KB Output is correct
40 Correct 296 ms 33272 KB Output is correct
41 Correct 143 ms 33272 KB Output is correct
42 Correct 126 ms 33272 KB Output is correct
43 Correct 109 ms 33272 KB Output is correct
44 Correct 373 ms 33272 KB Output is correct
45 Correct 339 ms 33272 KB Output is correct
46 Correct 389 ms 33272 KB Output is correct
47 Correct 376 ms 33272 KB Output is correct
48 Correct 373 ms 33272 KB Output is correct
49 Correct 553 ms 33272 KB Output is correct
50 Correct 599 ms 33272 KB Output is correct
51 Correct 573 ms 33272 KB Output is correct
52 Correct 576 ms 33272 KB Output is correct
53 Correct 719 ms 33272 KB Output is correct
54 Correct 619 ms 33272 KB Output is correct
55 Correct 863 ms 33272 KB Output is correct
56 Correct 783 ms 33272 KB Output is correct
57 Correct 789 ms 33272 KB Output is correct
58 Correct 873 ms 33272 KB Output is correct
59 Correct 916 ms 33272 KB Output is correct
60 Correct 893 ms 33272 KB Output is correct
61 Correct 753 ms 33272 KB Output is correct
62 Correct 823 ms 33272 KB Output is correct