답안 #700130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700130 2023-02-18T16:41:11 Z messiuuuuu Money (IZhO17_money) C++14
100 / 100
159 ms 14940 KB
///
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e6 + 5;
const ll INF = 1e18 + 5;

int n;
int a[MAXN];

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
}

struct BIT
{
    int fe[MAXN];

    void add(int id, int val)
    {
        for (; id <= 1e6; id += id & -id)
            fe[id] += val;
    }

    int get(int l)
    {
        if (l < 0)
            return 0;
        int res = 0;
        for (; l; l -= l & -l)
            res += fe[l];
        return res;
    }

    int get(int l, int r)
    {
        if (l > r)
            return 0;
        return get(r) - get(l - 1);
    }
}bit;

void Solve()
{
    int res = 1, pos = 1;
    for (int i = 1; i < n; i++)
    {
        if (a[i] > a[i + 1])
        {
            res++;
            while (pos <= i)
            {
                bit.add(a[pos], 1);
                pos++;
            }
        }
        if (a[i] < a[i + 1] && bit.get(a[pos] + 1, a[i + 1] - 1))
        {
            res++;
            while (pos <= i)
            {
                bit.add(a[pos], 1);
                pos++;
            }
        }
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 456 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 456 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 1604 KB Output is correct
38 Correct 1 ms 1736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 388 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 456 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 1604 KB Output is correct
38 Correct 1 ms 1736 KB Output is correct
39 Correct 53 ms 5376 KB Output is correct
40 Correct 89 ms 8984 KB Output is correct
41 Correct 55 ms 4408 KB Output is correct
42 Correct 45 ms 4236 KB Output is correct
43 Correct 31 ms 3056 KB Output is correct
44 Correct 114 ms 11000 KB Output is correct
45 Correct 106 ms 10960 KB Output is correct
46 Correct 114 ms 11212 KB Output is correct
47 Correct 121 ms 11076 KB Output is correct
48 Correct 104 ms 11096 KB Output is correct
49 Correct 133 ms 14940 KB Output is correct
50 Correct 140 ms 14924 KB Output is correct
51 Correct 117 ms 14796 KB Output is correct
52 Correct 113 ms 14884 KB Output is correct
53 Correct 109 ms 14828 KB Output is correct
54 Correct 129 ms 14812 KB Output is correct
55 Correct 119 ms 14836 KB Output is correct
56 Correct 117 ms 14872 KB Output is correct
57 Correct 118 ms 14796 KB Output is correct
58 Correct 130 ms 14784 KB Output is correct
59 Correct 118 ms 14872 KB Output is correct
60 Correct 132 ms 14872 KB Output is correct
61 Correct 159 ms 14892 KB Output is correct
62 Correct 124 ms 14912 KB Output is correct