Submission #362868

# Submission time Handle Problem Language Result Execution time Memory
362868 2021-02-04T14:16:52 Z shahriarkhan Money (IZhO17_money) C++14
100 / 100
747 ms 20204 KB
#include<bits/stdc++.h>
using namespace std ;

const int mx = 1e6 + 45 ;

struct tree
{
    vector<int> t ;

    tree(int n)
    {
        t = vector<int> (4*mx , 0) ;
    }

    void update(int node , int low , int high , int ind)
    {
        if(high<ind || low>ind) return ;

        if((low==high) && (high==ind))
        {
            ++t[node] ;
            return ;
        }

        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        update(left,low,mid,ind) ;
        update(right,mid+1,high,ind) ;
        t[node] = t[left] + t[right] ;
    }

    int find_max(int node , int low , int high , int l , int r)
    {
        if(l>r) return 0 ;
        if(l>high || r<low) return 0 ;
        if(l<=low && high<=r) return t[node] ;
        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        return find_max(left,low,mid,l,r) + find_max(right,mid+1,high,l,r) ;
    }
};

int main()
{
    int n ;
    scanf("%d",&n) ;
    int a[n+1] , ans = 0 ;
    for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
    tree T(mx+5) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        int ed = i ;
        while(((ed+1)<=n) && ((a[ed+1]>=a[ed]) && (!T.find_max(1,1,mx,a[i]+1,a[ed+1]-1)))) ++ed ;
        ++ans ;
        for(int j = i ; j <= ed ; ++j) T.update(1,1,mx,a[j]) ;
        i = ed ;
    }
    printf("%d\n",ans) ;
    return 0 ;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
money.cpp:46:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
      |                                   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 15980 KB Output is correct
4 Correct 10 ms 15980 KB Output is correct
5 Correct 10 ms 15980 KB Output is correct
6 Correct 10 ms 15980 KB Output is correct
7 Correct 10 ms 15980 KB Output is correct
8 Correct 10 ms 15980 KB Output is correct
9 Correct 10 ms 15980 KB Output is correct
10 Correct 10 ms 15980 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 10 ms 15980 KB Output is correct
13 Correct 10 ms 15980 KB Output is correct
14 Correct 10 ms 15980 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 10 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 15980 KB Output is correct
4 Correct 10 ms 15980 KB Output is correct
5 Correct 10 ms 15980 KB Output is correct
6 Correct 10 ms 15980 KB Output is correct
7 Correct 10 ms 15980 KB Output is correct
8 Correct 10 ms 15980 KB Output is correct
9 Correct 10 ms 15980 KB Output is correct
10 Correct 10 ms 15980 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 10 ms 15980 KB Output is correct
13 Correct 10 ms 15980 KB Output is correct
14 Correct 10 ms 15980 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 10 ms 15980 KB Output is correct
17 Correct 10 ms 16108 KB Output is correct
18 Correct 11 ms 15980 KB Output is correct
19 Correct 10 ms 15980 KB Output is correct
20 Correct 11 ms 15980 KB Output is correct
21 Correct 11 ms 15980 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 10 ms 16012 KB Output is correct
24 Correct 10 ms 15980 KB Output is correct
25 Correct 10 ms 15980 KB Output is correct
26 Correct 10 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 15980 KB Output is correct
4 Correct 10 ms 15980 KB Output is correct
5 Correct 10 ms 15980 KB Output is correct
6 Correct 10 ms 15980 KB Output is correct
7 Correct 10 ms 15980 KB Output is correct
8 Correct 10 ms 15980 KB Output is correct
9 Correct 10 ms 15980 KB Output is correct
10 Correct 10 ms 15980 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 10 ms 15980 KB Output is correct
13 Correct 10 ms 15980 KB Output is correct
14 Correct 10 ms 15980 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 10 ms 15980 KB Output is correct
17 Correct 10 ms 16108 KB Output is correct
18 Correct 11 ms 15980 KB Output is correct
19 Correct 10 ms 15980 KB Output is correct
20 Correct 11 ms 15980 KB Output is correct
21 Correct 11 ms 15980 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 10 ms 16012 KB Output is correct
24 Correct 10 ms 15980 KB Output is correct
25 Correct 10 ms 15980 KB Output is correct
26 Correct 10 ms 15980 KB Output is correct
27 Correct 10 ms 15980 KB Output is correct
28 Correct 10 ms 15980 KB Output is correct
29 Correct 12 ms 15980 KB Output is correct
30 Correct 13 ms 15980 KB Output is correct
31 Correct 12 ms 15980 KB Output is correct
32 Correct 10 ms 15980 KB Output is correct
33 Correct 10 ms 15980 KB Output is correct
34 Correct 11 ms 16000 KB Output is correct
35 Correct 10 ms 15980 KB Output is correct
36 Correct 10 ms 15980 KB Output is correct
37 Correct 10 ms 15980 KB Output is correct
38 Correct 12 ms 16108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 15980 KB Output is correct
4 Correct 10 ms 15980 KB Output is correct
5 Correct 10 ms 15980 KB Output is correct
6 Correct 10 ms 15980 KB Output is correct
7 Correct 10 ms 15980 KB Output is correct
8 Correct 10 ms 15980 KB Output is correct
9 Correct 10 ms 15980 KB Output is correct
10 Correct 10 ms 15980 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 10 ms 15980 KB Output is correct
13 Correct 10 ms 15980 KB Output is correct
14 Correct 10 ms 15980 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 10 ms 15980 KB Output is correct
17 Correct 10 ms 16108 KB Output is correct
18 Correct 11 ms 15980 KB Output is correct
19 Correct 10 ms 15980 KB Output is correct
20 Correct 11 ms 15980 KB Output is correct
21 Correct 11 ms 15980 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 10 ms 16012 KB Output is correct
24 Correct 10 ms 15980 KB Output is correct
25 Correct 10 ms 15980 KB Output is correct
26 Correct 10 ms 15980 KB Output is correct
27 Correct 10 ms 15980 KB Output is correct
28 Correct 10 ms 15980 KB Output is correct
29 Correct 12 ms 15980 KB Output is correct
30 Correct 13 ms 15980 KB Output is correct
31 Correct 12 ms 15980 KB Output is correct
32 Correct 10 ms 15980 KB Output is correct
33 Correct 10 ms 15980 KB Output is correct
34 Correct 11 ms 16000 KB Output is correct
35 Correct 10 ms 15980 KB Output is correct
36 Correct 10 ms 15980 KB Output is correct
37 Correct 10 ms 15980 KB Output is correct
38 Correct 12 ms 16108 KB Output is correct
39 Correct 193 ms 17772 KB Output is correct
40 Correct 342 ms 19052 KB Output is correct
41 Correct 163 ms 17536 KB Output is correct
42 Correct 157 ms 17456 KB Output is correct
43 Correct 114 ms 16908 KB Output is correct
44 Correct 413 ms 19948 KB Output is correct
45 Correct 427 ms 19820 KB Output is correct
46 Correct 422 ms 19820 KB Output is correct
47 Correct 381 ms 19948 KB Output is correct
48 Correct 397 ms 19948 KB Output is correct
49 Correct 584 ms 19820 KB Output is correct
50 Correct 562 ms 20204 KB Output is correct
51 Correct 578 ms 19948 KB Output is correct
52 Correct 556 ms 19948 KB Output is correct
53 Correct 569 ms 19948 KB Output is correct
54 Correct 593 ms 20076 KB Output is correct
55 Correct 721 ms 20076 KB Output is correct
56 Correct 729 ms 19996 KB Output is correct
57 Correct 699 ms 20000 KB Output is correct
58 Correct 707 ms 19948 KB Output is correct
59 Correct 714 ms 19984 KB Output is correct
60 Correct 721 ms 19820 KB Output is correct
61 Correct 747 ms 19948 KB Output is correct
62 Correct 728 ms 19944 KB Output is correct