玄关求调
查看原帖
玄关求调
644963
ln001楼主2024/7/9 20:34
// Problem: P3295 [SCOI2016] 萌萌哒
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3295
// Time Limit: 1000 ms
// Start Time:2024-07-09 16:00:36
//
// Powered by CP Editor (https://cpeditor.org)

#ifndef LOCAL
#include <bits/stdc++.h>
#define csf std::cerr.setstate(std::ios_base::failbit)
#define db(x)
#else
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#define db(x) cerr << __FUNCTION__ << " L" << __LINE__ << " " << #x " = " << (x) << endl
#define csf
#endif
#define ll long long
#define f(x, y, z) for (ll x = (y); x <= (z); x++)
using namespace std;
inline ll read();
const ll INF = 0x3f3f3f3f3f3f3f3f, N = 1e5 + 10, M = 20 + 20, P = 1e9 + 7;
ll n, m, ml;
ll pow2[M];
ll fa[N][M]; // i为首,长为2^j
ll fifa(ll x, ll y)
{
    if (fa[x][y] == x)
        return x;
    return fa[x][y] = fifa(fa[x][y], y);
}
signed main()
{
    csf;
    cin >> n >> m;
    ml = ceil(log2(n)) + 5;
    pow2[0] = 1;
    f(i, 1, ml)
    {
        pow2[i] = pow2[i - 1] * 2;
    }
    f(i, 1, n)
    {
        f(j, 0, ml)
        {
            if (i + pow2[j] - 1 > n)
                break;
            fa[i][j] = i;
        }
    }
    while (m--)
    {
        ll l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        ll len = ceil(log2(r1 - l1 + 1));
        ll lm1 = fifa(l1, len - 1), mr1 = fifa(r1 - pow2[len - 1] + 1, len - 1);
        ll lm2 = fifa(l2, len - 1), mr2 = fifa(r2 - pow2[len - 1] + 1, len - 1);
        fa[lm2][len - 1] = lm1;
        fa[mr2][len - 1] = mr1;
    }
    for (ll j = ml; j >= 1; j--)
    {
        ll len = pow2[j];
        f(i, 1, n)
        {
            if (i + pow2[j] - 1 > n)
                continue;
            if (fa[i][j] == i)
                continue;
            ll l1 = i, r1 = l1 + len - 1;
            ll l2 = fifa(i, j), r2 = l2 + len - 1;
            ll lm1 = fifa(l1, j - 1), mr1 = fifa(r1 - pow2[j - 1] + 1, j - 1);
            ll lm2 = fifa(l2, j - 1), mr2 = fifa(r2 - pow2[j - 1] + 1, j - 1);
            fa[lm2][len - 1] = lm1;
            fa[mr2][len - 1] = mr1;
        }
    }
    ll cnt = 0, ans = 9;
    f(i, 1, n)
    {
        if (fa[i][0] == i)
            cnt++;
    }
    f(i, 1, cnt - 1) ans = ans * 10 % P;
    cout << ans << endl;
    return 0;
}
inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    return x * f;
}

link

2024/7/9 20:34
加载中...