#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <functional>
#include <numeric>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> lnum;
const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double PI = acos((long double)-1.0);
const long double eps = 1e-8;
int T[4 * N];
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
T[v] += val;
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm) update(2 * v + 1, tl, tm, pos, val);
else update(2 * v + 2, tm + 1, tr, pos, val);
T[v] = T[2 * v + 1 ] + T[2 * v + 2];
}
int query(int v, int tl, int tr, int l, int r) {
if (l > r) return 0;
if (tl == l && tr == r) return T[v];
int tm = (tl + tr) >> 1;
return query(2 * v + 1, tl, tm, l, min(r, tm)) +
query(2 * v + 2, tm + 1, tr, max(l, tm + 1), r);
}
void solve() {
int n, ans = 0; cin >> n;
vector <int> V(n);
for (int i = 0; i < n; ++i) {
cin >> V[i];
}
for (int i = 0; i < n;) {
++ans;
int j = i;
for (; j + 1 < n && V[j] <= V[j + 1] && !query(0, 0, N - 1, V[i] + 1, V[j + 1] - 1);) ++j;
for (; i <= j && i < n; ++i) {
update(0, 0, N - 1, V[i], 1);
}
}
cout << ans << endl;
}
/*
6
3 6 4 5 1 2
*/
int main() {
//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
//#define Freopen
#ifdef Freopen
#ifndef _MSC_VER
#define TASK ""
freopen(TASK".in", "r", stdin);
freopen(TASK".out", "w", stdout);
#endif
#endif
int T = 1;
//scanf("%d", &T);
for (; T; --T) solve();
#ifdef DEBUG
cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif
return 0;
}
Compilation message
money.cpp:36:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable:4996)
money.cpp:37:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/STACK:20000007")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
672 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
672 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
960 KB |
Output is correct |
19 |
Correct |
2 ms |
960 KB |
Output is correct |
20 |
Correct |
2 ms |
960 KB |
Output is correct |
21 |
Correct |
2 ms |
960 KB |
Output is correct |
22 |
Correct |
2 ms |
960 KB |
Output is correct |
23 |
Correct |
2 ms |
960 KB |
Output is correct |
24 |
Correct |
2 ms |
960 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
672 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
960 KB |
Output is correct |
19 |
Correct |
2 ms |
960 KB |
Output is correct |
20 |
Correct |
2 ms |
960 KB |
Output is correct |
21 |
Correct |
2 ms |
960 KB |
Output is correct |
22 |
Correct |
2 ms |
960 KB |
Output is correct |
23 |
Correct |
2 ms |
960 KB |
Output is correct |
24 |
Correct |
2 ms |
960 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
27 |
Correct |
2 ms |
1168 KB |
Output is correct |
28 |
Correct |
2 ms |
1168 KB |
Output is correct |
29 |
Correct |
2 ms |
1168 KB |
Output is correct |
30 |
Correct |
2 ms |
1168 KB |
Output is correct |
31 |
Correct |
2 ms |
1168 KB |
Output is correct |
32 |
Correct |
2 ms |
1168 KB |
Output is correct |
33 |
Correct |
2 ms |
1168 KB |
Output is correct |
34 |
Correct |
2 ms |
1168 KB |
Output is correct |
35 |
Correct |
2 ms |
1168 KB |
Output is correct |
36 |
Correct |
2 ms |
1168 KB |
Output is correct |
37 |
Correct |
4 ms |
3264 KB |
Output is correct |
38 |
Correct |
4 ms |
3264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
672 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
960 KB |
Output is correct |
19 |
Correct |
2 ms |
960 KB |
Output is correct |
20 |
Correct |
2 ms |
960 KB |
Output is correct |
21 |
Correct |
2 ms |
960 KB |
Output is correct |
22 |
Correct |
2 ms |
960 KB |
Output is correct |
23 |
Correct |
2 ms |
960 KB |
Output is correct |
24 |
Correct |
2 ms |
960 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
27 |
Correct |
2 ms |
1168 KB |
Output is correct |
28 |
Correct |
2 ms |
1168 KB |
Output is correct |
29 |
Correct |
2 ms |
1168 KB |
Output is correct |
30 |
Correct |
2 ms |
1168 KB |
Output is correct |
31 |
Correct |
2 ms |
1168 KB |
Output is correct |
32 |
Correct |
2 ms |
1168 KB |
Output is correct |
33 |
Correct |
2 ms |
1168 KB |
Output is correct |
34 |
Correct |
2 ms |
1168 KB |
Output is correct |
35 |
Correct |
2 ms |
1168 KB |
Output is correct |
36 |
Correct |
2 ms |
1168 KB |
Output is correct |
37 |
Correct |
4 ms |
3264 KB |
Output is correct |
38 |
Correct |
4 ms |
3264 KB |
Output is correct |
39 |
Correct |
289 ms |
6088 KB |
Output is correct |
40 |
Correct |
488 ms |
12896 KB |
Output is correct |
41 |
Correct |
233 ms |
13644 KB |
Output is correct |
42 |
Correct |
225 ms |
16112 KB |
Output is correct |
43 |
Correct |
154 ms |
17400 KB |
Output is correct |
44 |
Correct |
597 ms |
26952 KB |
Output is correct |
45 |
Correct |
605 ms |
33684 KB |
Output is correct |
46 |
Correct |
610 ms |
40404 KB |
Output is correct |
47 |
Correct |
612 ms |
47204 KB |
Output is correct |
48 |
Correct |
627 ms |
54072 KB |
Output is correct |
49 |
Correct |
776 ms |
69024 KB |
Output is correct |
50 |
Correct |
780 ms |
75840 KB |
Output is correct |
51 |
Correct |
798 ms |
82312 KB |
Output is correct |
52 |
Correct |
873 ms |
89380 KB |
Output is correct |
53 |
Correct |
911 ms |
96088 KB |
Output is correct |
54 |
Correct |
774 ms |
102624 KB |
Output is correct |
55 |
Correct |
985 ms |
109492 KB |
Output is correct |
56 |
Correct |
952 ms |
116192 KB |
Output is correct |
57 |
Correct |
970 ms |
122968 KB |
Output is correct |
58 |
Correct |
961 ms |
129624 KB |
Output is correct |
59 |
Correct |
968 ms |
136312 KB |
Output is correct |
60 |
Correct |
952 ms |
143184 KB |
Output is correct |
61 |
Correct |
937 ms |
149944 KB |
Output is correct |
62 |
Correct |
950 ms |
156688 KB |
Output is correct |