Submission #61638323


Source Code Expand

#ifdef ONPC
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3")
#endif

// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cassert>
#include <tuple>
#include <iostream>
#include <set>
#include <stdexcept>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define int ll

using namespace std;

typedef int64_t ll;
// typedef __int128_t lll;
typedef uint64_t ull;
typedef long double ld;

template <typename T>
void PrintV(vector<T> v)
{
    for (T x : v)
    {
        cout << x << " ";
    }
    cout << "\n";
}

ll GCD(ll a, ll b)
{
    if (b == 0)
    {
        return abs(a);
    }
    return GCD(b, a % b);
}

const ll mod = 998244353; // 1e9 + 7; // 998244353;

ll sum(ll a, ll b)
{
    return (a + b) % mod;
}

ll mult(ll a, ll b)
{
    return (a * b) % mod;
}

ll binpow(ll x, ll pw)
{
    if (pw == 0)
    {
        return 1;
    }
    ll res = binpow(mult(x, x), pw / 2);
    if (pw & 1)
    {
        return mult(res, x);
    }
    return res;
}

// vector<pair<int, int>> nx = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

// const ll maxf = 2e6;

// ll fact[maxf], ifact[maxf];

// void precalc()
// {
//     fact[0] = 1;
//     for (int i = 1; i < maxf; ++i)
//     {
//         fact[i] = mult(i, fact[i - 1]);
//     }
//     ifact[maxf - 1] = binpow(fact[maxf - 1], mod - 2);
//     for (int i = maxf - 1; i > 0; --i)
//     {
//         ifact[i - 1] = mult(ifact[i], i);
//     }
//     assert(ifact[0] == 1);
// }

// ll C(int n, int k)
// {
//     if (n < k || k < 0)
//         return 0;
//     return mult(fact[n], mult(ifact[n - k], ifact[k]));
// }

// ll P(int n, int k)
// {
//     if (k <= 0)
//         return 0;
//     return C(n + k - 1, k - 1);
// }

// struct pt
// {
//     ll x, y;
//     pt operator-(pt r) const
//     {
//         return {x - r.x, y - r.y};
//     }
//     pt operator+(pt r) const
//     {
//         return {x + r.x, y + r.y};
//     }
//     ll dist2(pt r) const
//     {
//         return (x - r.x) * (x - r.x) + (y - r.y) * (y - r.y);
//     }
// };
// struct line
// {
//     ll a, b, c;
//     line(ll a_, ll b_, ll c_) : a(a_), b(b_), c(c_)
//     {
//     }
//     line(const pt &f, const pt &s)
//         : a(f.y - s.y), b(s.x - f.x), c(-a * f.x - b * f.y) {}
//     ld val(const pt &p) const { return a * p.x + b * p.y + c; }
// };
// ld operator*(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; }
// ld operator^(const pt &a, const pt &b) { return a.x * b.y - b.x * a.y; }

// bool isCw(const pt &a, const pt &b, const pt &c) { return ((b - a) ^ (c - a)) < 0; }
// bool isCcw(const pt &a, const pt &b, const pt &c) { return 0 < ((b - a) ^ (c - a)); }

// struct pt
// {
//     ll x, y;

//     ll dst2(pt A)
//     {
//         return (A.x - x) * (A.x - x) + (A.y - y) * (A.y - y);
//     }
// };

// const int maxn = (1 << 20);
// int a[maxn], sum[maxn];

// const int maxc = 22;
// int C[maxc][maxc];

// typedef bitset<100> bs;

// vector<char> is_prime;
// const int mxpr = 5e5;

// void prec()
// {
//     is_prime.assign(mxpr, true);
//     is_prime[0] = false;
//     is_prime[1] = false;
//     forn(i, mxpr)
//     {
//         if (is_prime[i])
//         {
//             for (int j = 2; j * i < mxpr; ++j)
//             {
//                 is_prime[j * i] = false;
//             }
//         }
//     }
// }

const ll maxn = 404;
const ll inf = 1e9;

mt19937 gen(0);

struct SegTr
{
    vector<ll> tr;

    SegTr(ll n) : tr(4 * n)
    {
    }

    void Set(ll i, ll val, ll tv, ll l, ll r)
    {
        if (l > i || r <= i)
        {
            return;
        }
        if (l + 1 == r)
        {
            tr[tv] = val;
            return;
        }
        ll md = (l + r) / 2;
        Set(i, val, 2 * tv, l, md);
        Set(i, val, 2 * tv + 1, md, r);
        tr[tv] = tr[2 * tv] + tr[2 * tv + 1];
    }

    ll Get(ll p, ll v, ll l, ll r)
    {
        if (p <= l)
        {
            return 0;
        }
        if (p >= r)
            return tr[v];
        ll md = (l + r) / 2;
        return Get(p, 2 * v, l, md) + Get(p, 2 * v + 1, md, r);
    }
};

void Solve()
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> segs;
    int i0 = -1;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;
        l--;
        segs.push_back({l, r, i});

        if (l == 0 && r == n)
        {
            i0 = i;
        }
    }
    if (i0 >= 0)
    {
        cout << "1\n";
        forn(i, m)
        {
            if (i == i0)
            {
                cout << "1 ";
            }
            else
            {
                cout << "0 ";
            }
        }
        return;
    }
    sort(segs.begin(), segs.end(), [](tuple<int, int, int> l, tuple<int, int, int> r)
         { 
            if (get<0>(l) != get<0>(r) ) 
                return get<0>(l) < get<0>(r);
            return  get<1>(l) >get<1>(r); });
    // int last = -1;

    forn(j, m)
    {
        if (j > 0)
        {
            if (get<1>(segs[j]) <= get<1>(segs[j - 1]))
            {
                int i1 = get<2>(segs[j]);
                int i2 = get<2>(segs[j - 1]);
                cout << "2\n";
                forn(i, m)
                {
                    if (i != i1 && i != i2)
                    {
                        cout << "0 ";
                    }
                    else if (i == i1)
                    {
                        cout << "2 ";
                    }
                    else
                    {

                        cout << "1 ";
                    }
                }
                return;
            }
        }
    }
    if (get<1>(segs[0]) <= get<0>(segs[m - 1]))
    {
        int i1 = get<2>(segs[m - 1]);
        int i2 = get<2>(segs[0]);
        cout << "2\n";
        forn(i, m)
        {
            if (i != i1 && i != i2)
            {
                cout << "0 ";
            }
            else if (i == i1)
            {
                cout << "2 ";
            }
            else
            {

                cout << "2 ";
            }
        }
        return;
    }

    if (get<0>(segs[0]) == 0 && get<1>(segs[m - 1]) == n)
    {
        int i1 = get<2>(segs[m - 1]);
        int i2 = get<2>(segs[0]);
        cout << "2\n";
        forn(i, m)
        {
            if (i != i1 && i != i2)
            {
                cout << "0 ";
            }
            else if (i == i1)
            {
                cout << "1 ";
            }
            else
            {

                cout << "1 ";
            }
        }
        return;
    }

    if (m < 3)
    {
        cout << "-1\n";
        return;
    }

    int i1 = get<2>(segs[0]);
    int i2 = get<2>(segs[1]);
    int i3 = get<2>(segs[2]);

    cout << "3\n";
    forn(i, m)
    {
        if (i != i1 && i != i2 && i != i3)
        {
            cout << "0 ";
        }
        else if (i == i2)
        {
            cout << "1 ";
        }
        else
        {
            cout << "2 ";
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    cout << setprecision(15);
    // prec();
    int q = 1;
    // cin >> q;
    while (q--)
    {
        Solve();
    }
    return 0;
}

Submission Info

Submission Time
Task A - Inside or Outside
User Paliukh
Language C++ 20 (gcc 12.2)
Score 700
Code Size 8160 Byte
Status AC
Exec Time 39 ms
Memory 9456 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 4
AC × 67
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 02_small_15.txt, 02_small_16.txt, 02_small_17.txt, 03_max_rand_1_01.txt, 03_max_rand_1_02.txt, 03_max_rand_1_03.txt, 03_max_rand_1_04.txt, 03_max_rand_1_05.txt, 04_max_rand_2_01.txt, 04_max_rand_2_02.txt, 04_max_rand_2_03.txt, 04_max_rand_2_04.txt, 04_max_rand_2_05.txt, 05_one_01.txt, 05_one_02.txt, 06_three_01.txt, 06_three_02.txt, 06_three_03.txt, 06_three_04.txt, 06_three_05.txt, 06_three_06.txt, 06_three_07.txt, 06_three_08.txt, 06_three_09.txt, 06_three_10.txt, 07_two_01.txt, 07_two_02.txt, 07_two_03.txt, 07_two_04.txt, 07_two_05.txt, 07_two_06.txt, 07_two_07.txt, 07_two_08.txt, 07_two_09.txt, 07_two_10.txt, 07_two_11.txt, 07_two_12.txt, 07_two_13.txt, 07_two_14.txt, 07_two_15.txt, 07_two_16.txt, 07_two_17.txt, 07_two_18.txt, 07_two_19.txt, 08_special_01.txt, 08_special_02.txt, 08_special_03.txt, 08_special_04.txt, 08_special_05.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3432 KiB
01_sample_02.txt AC 1 ms 3472 KiB
01_sample_03.txt AC 1 ms 3472 KiB
01_sample_04.txt AC 1 ms 3396 KiB
02_small_01.txt AC 1 ms 3424 KiB
02_small_02.txt AC 1 ms 3480 KiB
02_small_03.txt AC 1 ms 3424 KiB
02_small_04.txt AC 1 ms 3420 KiB
02_small_05.txt AC 1 ms 3476 KiB
02_small_06.txt AC 1 ms 3484 KiB
02_small_07.txt AC 1 ms 3444 KiB
02_small_08.txt AC 1 ms 3416 KiB
02_small_09.txt AC 1 ms 3388 KiB
02_small_10.txt AC 1 ms 3476 KiB
02_small_11.txt AC 1 ms 3488 KiB
02_small_12.txt AC 1 ms 3428 KiB
02_small_13.txt AC 1 ms 3544 KiB
02_small_14.txt AC 1 ms 3552 KiB
02_small_15.txt AC 1 ms 3496 KiB
02_small_16.txt AC 1 ms 3504 KiB
02_small_17.txt AC 3 ms 3728 KiB
03_max_rand_1_01.txt AC 38 ms 9340 KiB
03_max_rand_1_02.txt AC 37 ms 9296 KiB
03_max_rand_1_03.txt AC 37 ms 9300 KiB
03_max_rand_1_04.txt AC 37 ms 9216 KiB
03_max_rand_1_05.txt AC 37 ms 9356 KiB
04_max_rand_2_01.txt AC 38 ms 9332 KiB
04_max_rand_2_02.txt AC 37 ms 9340 KiB
04_max_rand_2_03.txt AC 37 ms 9448 KiB
04_max_rand_2_04.txt AC 37 ms 9448 KiB
04_max_rand_2_05.txt AC 38 ms 9340 KiB
05_one_01.txt AC 21 ms 9276 KiB
05_one_02.txt AC 12 ms 6168 KiB
06_three_01.txt AC 30 ms 9304 KiB
06_three_02.txt AC 36 ms 9260 KiB
06_three_03.txt AC 36 ms 9308 KiB
06_three_04.txt AC 10 ms 4748 KiB
06_three_05.txt AC 34 ms 9292 KiB
06_three_06.txt AC 19 ms 6192 KiB
06_three_07.txt AC 24 ms 6076 KiB
06_three_08.txt AC 4 ms 4036 KiB
06_three_09.txt AC 36 ms 9316 KiB
06_three_10.txt AC 28 ms 9388 KiB
07_two_01.txt AC 38 ms 9344 KiB
07_two_02.txt AC 38 ms 9296 KiB
07_two_03.txt AC 39 ms 9296 KiB
07_two_04.txt AC 38 ms 9456 KiB
07_two_05.txt AC 38 ms 9288 KiB
07_two_06.txt AC 38 ms 9340 KiB
07_two_07.txt AC 38 ms 9300 KiB
07_two_08.txt AC 38 ms 9300 KiB
07_two_09.txt AC 38 ms 9312 KiB
07_two_10.txt AC 38 ms 9324 KiB
07_two_11.txt AC 39 ms 9452 KiB
07_two_12.txt AC 38 ms 9360 KiB
07_two_13.txt AC 38 ms 9452 KiB
07_two_14.txt AC 38 ms 9344 KiB
07_two_15.txt AC 38 ms 9356 KiB
07_two_16.txt AC 38 ms 9296 KiB
07_two_17.txt AC 37 ms 9452 KiB
07_two_18.txt AC 38 ms 9308 KiB
07_two_19.txt AC 38 ms 9296 KiB
08_special_01.txt AC 26 ms 9452 KiB
08_special_02.txt AC 26 ms 9316 KiB
08_special_03.txt AC 1 ms 3388 KiB
08_special_04.txt AC 1 ms 3468 KiB
08_special_05.txt AC 1 ms 3468 KiB