답안 #886469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886469 2023-12-12T08:03:37 Z boris_mihov Money (IZhO17_money) C++17
0 / 100
1 ms 2396 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
#include <stack>

typedef long long llong;
const int MAXN = 1000000 + 10;

int n;
int a[MAXN];
int b[MAXN];
std::stack <int> st;

void solve()
{
    std::iota(b + 1, b + 1 + n, 1);
    std::sort(b + 1, b + 1 + n, [&](int x, int y)
    {
        return a[x] < a[y] || (a[x] == a[y] & x < y);
    });

    for (int i = 1 ; i <= n ; ++i)
    {
        a[b[i]] = i;
    }

    int ans = 0;
    for (int i = 1 ; i <= n ; ++i)
    {
        while (st.size() && a[st.top()] > a[i])
        {
            st.pop();
        }

        ans += (st.empty() || a[st.top()] + 1 < a[i]);
        st.push(i);
    }

    std::cout << ans << '\n';
}

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

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}

Compilation message

money.cpp: In lambda function:
money.cpp:22:37: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   22 |         return a[x] < a[y] || (a[x] == a[y] & x < y);
      |                                ~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -