Logo wfirstzhang的博客

博客

#410. 倍数点更新 题目资源

2025-09-20 07:24:58 By wfirstzhang

410data

#include <ctime>
#include <fstream>
#include <random>
#include <string>
#include <vector>

int main() {
    using namespace std;

    random_device seed;
    mt19937 rnd(seed());
    uniform_int_distribution<long> nm_dist(1, 100000);
    uniform_real_distribution<double> qu_dist(0, 1);
    uniform_int_distribution<long> numtyp_dist(0, 3);
    uniform_int_distribution<long> qnum_dist(1, 1000000000);
    double query = 0.0;
    for (int t = 1; t < 25; t++, query += 0.04)
    {
        ofstream iout("./data/random" + to_string(t) + ".in");
        ofstream oout("./data/random" + to_string(t) + ".out");
        int64_t n = nm_dist(rnd), m = nm_dist(rnd);
        uniform_int_distribution<int64_t> lr_dist(1, n);
        uniform_int_distribution<int64_t> sk_dist(1, max<int>(log2(n), 1));
        uniform_real_distribution<double> num_dist(0, 1);
        uniform_int_distribution<int64_t> hi_dist(max<int>(log2(n), 1), n);
        uniform_int_distribution<int64_t> norm_dist(1, n);
        long numtyp = numtyp_dist(rnd);
        iout << n << ' ' << m << endl;
        vector<long> arr(n + 1, 0);
        while (m--)
        {
            if (qu_dist(rnd) < query)
            {
                long a, b = qnum_dist(rnd);
                switch (numtyp)
                {
                    case 0:
                        a = sk_dist(rnd);
                        break;
                    case 1:
                        a = pow(n, num_dist(rnd));
                        break;
                    case 2:
                        a = norm_dist(rnd);
                    default:
                        a = hi_dist(rnd);
                        break;
                }
                iout << 1 << ' ' << a << ' ' << b << endl;
                for (int i = 1; i * a <= n; i++)
                    arr[i * a] += b;
            }
            else
            {
                long a = lr_dist(rnd), b = lr_dist(rnd);
                if (a > b)
                    swap(a, b);
                iout << 2 << ' ' << a << ' ' << b << endl;
                long res = 0;
                for (long i = a; i <= b; i++)
                    res += arr[i];
                oout << res << endl;
            }
        }
    }
    return 0;
}

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。