답안 #700076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700076 2023-02-18T15:46:08 Z messiuuuuu Money (IZhO17_money) C++17
0 / 100
1 ms 340 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], 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 1 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -