抄的别人的快读,真快

65ms

#include <bits/stdc++.h>

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define LL long long
#define f(i, a, b) for (int i = a; i <= b; i++)
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))
#define fi first
#define se second
typedef unsigned long long ull;
struct FastIO
{
    static const int S = 5 << 20; //MB
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar()
    {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len)
            return -1;
        return buf[pos++];
    }
    inline int xuint()
    {
        int c = xchar(), x = 0;
        while (~c && c <= 32)
            c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar())
            x = x * 10 + c - '0';
        return x;
    }
    inline LL xull()
    {
        int c = xchar();
        LL x = 0;
        while (~c && c <= 32)
            c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar())
            x = x * 10 + c - '0';
        return x;
    }
    inline int xint()
    {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32)
            c = xchar();
        if (c == '-')
            s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar())
            x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s)
    {
        int c = xchar();
        while (c <= 32)
            c = xchar();
        for (; c > 32; c = xchar())
            *s++ = c;
        *s = 0;
    }
    inline void wchar(int x)
    {
        if (wpos == S)
            fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos++] = x;
    }
    inline void wll(LL x)
    {
        if (x < 0)
            wchar('-'), x = -x;

        char s[30];
        int n = 0;
        while (x || !n)
            s[n++] = '0' + x % 10, x /= 10;
        while (n--)
            wchar(s[n]);
    }
    inline void wstring(const char *s)
    {
        while (*s)
            wchar(*s++);
    }
    ~FastIO()
    {
        if (wpos)
            fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;

LL left[100086], right[100086], leftc[100086], rightc[100086], res = 0, cntl = 2, cntr = 1, fz = 1;
int x, last, now;

int main()
{
    IN;
    OUT;
    x  = io.xuint();
    last = io.xuint();
    left[1] = 1;
    leftc[1] = last - 1;
    res += last - 1;
    f(i, 2, x)
    {
        now = io.xuint();
        if (now > last)
        {
            res += now - last;
            left[cntl] = i;
            leftc[cntl++] = now - last;
        }
        if (now < last)
        {
            right[cntr] = i;
            rightc[cntr++] = last - now;
        }
        last = now;
    }
    io.wll(res);
    f(i, 1, cntl - 1)
    {
        while (leftc[i]--)
        {
            io.wchar('\n');
            io.wll(left[i]);
            io.wchar(' ');
            if (rightc[fz] > 0)
            {
                io.wll(right[fz] - 1);
                rightc[fz] -= 1;
                if (rightc[fz] == 0)
                    fz += 1;
            }
            else
                io.wll(x);
        }
    }
    return 0;
}
此文章已被阅读次数:正在加载...更新于