社区讨论

卡常能过(乐)

P1020[NOIP 1999 提高组] 导弹拦截参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lpovjkrj
此快照首次捕获于
2023/12/03 10:39
2 年前
此快照最后确认于
2023/12/03 12:31
2 年前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;

const int manx = 500005;
int a[manx], dp[manx], maxn;
int b[manx], cnt, x, l, n;

namespace IO
{
    using namespace std;
    template <const int N = (1 << 20)>
    class iqstream
    {
    private:
        FILE *fp = nullptr;
        char buf[N];
        char *it = nullptr, *is = nullptr;
        inline int gc()
        {
            return is == it ? (is = buf, it = buf + fread(buf, 1, N, fp), (is == it ? EOF : *is++)) : *is++;
        }

    public:
        inline iqstream &operator>>(char &c)
        {
            c = gc();
            while (c != EOF && isspace(c))
                c = gc();
            return *this;
        }
        template <typename T>
        inline iqstream &operator>>(T &x)
        {
            char c = gc();
            x = 0;
            bool f = 0;
            for (; !isdigit(c); c = gc())
                f ^= !(c ^ 45);
            for (; isdigit(c); c = gc())
                x = (x << 1) + (x << 3) + (c ^ 48);
            if (f)
                x = -x;
            return *this;
        }
        inline iqstream &operator>>(char *s)
        {
            int num = 0;
            char c = gc();
            while (c != EOF && isspace(c))
                c = gc();
            while (c != EOF && !isspace(c))
                s[num++] = c, c = gc();
            s[num] = '\0';
            return *this;
        }
        iqstream(FILE *p = stdin)
        {
            fp = p;
        }
        ~iqstream()
        {
            if (fp != stdin)
                fclose(fp);
        }
    };
    template <const int N = (1 << 20)>
    class oqstream
    {
    private:
        FILE *fp = nullptr;
        char buf[N];
        char *os = buf, *ot = buf + N - 1;
        inline void pc(char x)
        {
            *os++ = x;
            if (os == ot)
                this->flush();
        }
        char stk[65];

    public:
        oqstream(FILE *p = stdout)
        {
            if (p != nullptr)
                fp = p;
        }
        ~oqstream()
        {
            this->flush();
            if (fp != stdout && fp != stderr)
                fclose(fp);
        }
        inline void flush()
        {
            fwrite(buf, 1, os - buf, fp);
            os = buf;
        }
        inline oqstream &operator<<(char x)
        {
            pc(x);
            return *this;
        }
        inline oqstream &operator<<(const char *s)
        {
            int tot = 0;
            while (s[tot] != '\0')
                pc(s[tot++]);
            return *this;
        }
        template <typename T>
        inline oqstream &operator<<(T x)
        {
            if (!x)
                pc('0');
            else
            {
                if (x < 0)
                    pc('-'), x = -x;
                int top = 0;
                while (x)
                    stk[++top] = x % 10 + '0', x /= 10;
                while (top)
                    pc(stk[top--]);
            }
            return *this;
        }
    };
}

int main()
{
    static IO::iqstream<> qin;
    static IO::oqstream<> qout;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while (cin >> x)
        a[++l] = x;
    for (register int i = 1; i <= l; i++)
    {
        int j = 1;
        while (j <= cnt && b[j] >= a[i])
            j++;
        if (j > cnt)
            b[++cnt] = a[i];
        else
            b[j] = a[i];
    }
    qout << cnt << "\n";

    cnt = 0;
    for (register int i = 1; i <= l; i++)
    {
        int j = 1;
        while (j <= cnt && b[j] < a[i])
            j++;
        if (j > cnt)
            b[++cnt] = a[i];
        else
            b[j] = a[i];
    }
    qout << cnt;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...