Submission #533272

# Submission time Handle Problem Language Result Execution time Memory
533272 2022-03-05T08:22:40 Z christinelynn Money (IZhO17_money) C++17
100 / 100
1026 ms 56656 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double db;
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
 
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define repp(i,a,b) for(ll i = (a); i <= (b); i++)
#define repm(i, a, b) for (ll i = (a); i >= (b); i--)
#define repz(i, a, b) for (ll i = (a); i < (b); i++)
 
const long long MOD = 1e9+7, N = 1e6 + 5, M = 1e3+5, INF = 1e9; 

ll tc = 1, n, m,k,ar[N];
string s, ye = "YES", no = "NO", nu;
vector<pairll> ed[2], blu;

void fastt(){  
  ios_base::sync_with_stdio(0); 
  cin.tie(NULL);
  cout.tie(NULL);  
}

void input(){
  cin >> n;
  ar[0] = 0;
  repp(i,1,n) cin >> ar[i];
} 

void solve(){
  set<ll> stz;
  ll ans = 1, pre, ri = 1e18;
  repp(i,1,n){
    bool chen = 0; 
    if(ar[i] < ar[i-1]){
      chen = 1;
    }
    else{
      if(ri < ar[i]) chen = 1;
    }

    stz.insert(ar[i]);
    if(chen){
      ans++;
      auto it = stz.lower_bound(ar[i]);
      it++;
      if (it == stz.end()) ri = 1e18;
      else ri = *it;
    }
  }
  cout << ans << endl;
}

int main(){
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  fastt();
  while(tc--){
    input();
    solve();
  }
}

/*
3
1 2 3

1 2 3

5
2 8 6 3 1
1 2 3 6 8

(n-1)/2

*/

Compilation message

money.cpp: In function 'void solve()':
money.cpp:37:15: warning: unused variable 'pre' [-Wunused-variable]
   37 |   ll ans = 1, pre, ri = 1e18;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 70 ms 6152 KB Output is correct
40 Correct 103 ms 9436 KB Output is correct
41 Correct 39 ms 4840 KB Output is correct
42 Correct 43 ms 4296 KB Output is correct
43 Correct 28 ms 3616 KB Output is correct
44 Correct 112 ms 10948 KB Output is correct
45 Correct 111 ms 11084 KB Output is correct
46 Correct 121 ms 11084 KB Output is correct
47 Correct 97 ms 10996 KB Output is correct
48 Correct 138 ms 11036 KB Output is correct
49 Correct 432 ms 29552 KB Output is correct
50 Correct 448 ms 28204 KB Output is correct
51 Correct 419 ms 28108 KB Output is correct
52 Correct 459 ms 28108 KB Output is correct
53 Correct 429 ms 28088 KB Output is correct
54 Correct 450 ms 28092 KB Output is correct
55 Correct 989 ms 56536 KB Output is correct
56 Correct 1020 ms 56576 KB Output is correct
57 Correct 1026 ms 56608 KB Output is correct
58 Correct 957 ms 56528 KB Output is correct
59 Correct 967 ms 56628 KB Output is correct
60 Correct 960 ms 56652 KB Output is correct
61 Correct 961 ms 56552 KB Output is correct
62 Correct 976 ms 56656 KB Output is correct