首页 > 其他分享 >2025.1.16——1200

2025.1.16——1200

时间:2025-01-17 19:00:56浏览次数:1  
标签:integers 2025.1 16 int cdot 1200 leq ldots color

2025.1.16——1200


Q1. 1200

You are given \(3\) integers — \(n\), \(x\), \(y\). Let's call the score of a permutation\(^\dagger\) \(p_1, \ldots, p_n\) the following value:

\[(p_{1 \cdot x} + p_{2 \cdot x} + \ldots + p_{\lfloor \frac{n}{x} \rfloor \cdot x}) - (p_{1 \cdot y} + p_{2 \cdot y} + \ldots + p_{\lfloor \frac{n}{y} \rfloor \cdot y}) \]

In other words, the score of a permutation is the sum of \(p_i\) for all indices \(i\) divisible by \(x\), minus the sum of \(p_i\) for all indices \(i\) divisible by \(y\).

You need to find the maximum possible score among all permutations of length \(n\).

For example, if \(n = 7\), \(x = 2\), \(y = 3\), the maximum score is achieved by the permutation \([2,\color{red}{\underline{\color{black}{6}}},\color{blue}{\underline{\color{black}{1}}},\color{red}{\underline{\color{black}{7}}},5,\color{blue}{\underline{\color{red}{\underline{\color{black}{4}}}}},3]\) and is equal to \((6 + 7 + 4) - (1 + 4) = 17 - 5 = 12\).

\(^\dagger\) A permutation of length \(n\) is an array consisting of \(n\) distinct integers from \(1\) to \(n\) in any order. For example, \([2,3,1,5,4]\) is a permutation, but \([1,2,2]\) is not a permutation (the number \(2\) appears twice in the array) and \([1,3,4]\) is also not a permutation (\(n=3\), but the array contains \(4\)).
Input

The only line of each test case description contains \(3\) integers \(n\), \(x\), \(y\) (\(1 \le n \le 10^9\), \(1 \le x, y \le n\)).


Q2. 1200

You are given two arrays of integers — \(a_1, \ldots, a_n\) of length \(n\), and \(b_1, \ldots, b_m\) of length \(m\). You can choose any element \(b_j\) from array \(b\) (\(1 \leq j \leq m\)), and for all \(1 \leq i \leq n\) perform \(a_i = a_i | b_j\). You can perform any number of such operations.

After all the operations, the value of \(x = a_1 \oplus a_2 \oplus \ldots \oplus a_n\) will be calculated. Find the minimum and maximum values of \(x\) that could be obtained after performing any set of operations.

Above, \(|\) is the bitwise OR operation, and \(\oplus\) is the bitwise XOR operation.
Input

The first line of each test case contains two integers \(n\) and \(m\) (\(1 \leq n, m \leq 2 \cdot 10^5\)) — the sizes of arrays \(a\) and \(b\).

The second line of each test case contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(0 \leq a_i \leq 10^9\)) — the array \(a\).

The third line of each test case contains \(m\) integers \(b_1, b_2, \ldots, b_m\) (\(0 \leq b_i \leq 10^9\)) — the array \(b\).


------------------------思考------------------------

  • 数学/结论+位运算


A1

  1. 发现结论:除了共有的位置,计算个数分别分配最大值与最小值。
  2. 共有的位置是最小公倍数占的位置。

A2

  1. 位运算:保存 \(b\) 数组的每一位,相当于将原异或和值的某一位进行 \(0/1\) 互换。
  2. 奇数时可使原值变大,偶数时可使原值减小。

------------------------代码------------------------

A1

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, x, y;
    cin >> n >> x >> y;
    int hasx = n / x, hasy = n / y;
    int hasxy = n / (x * y / __gcd(x, y));
    hasx -= hasxy;
    hasy -= hasxy;
    // bug3(hasx, hasy, hasxy);
    auto get = [](int st, int ed)
    {
        int cnt = ed - st + 1;
        return (st + ed) * cnt / 2;
    };
    cout << get(n - hasx + 1, n) - get(1, hasy) << endl;
}

A2

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, m;
    cin >> n >> m;
    int _xor = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        _xor ^= x;
    }
    map<int, bool> has_bit;
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        for (int j = 0; x >> j; j++)
            if (x >> j & 1) // wa
                has_bit[j] = 1;
    }
    int mx = _xor, mn = _xor;
    if (n & 1)
    {
        for (auto [bit, has] : has_bit)
        {
            if (mx >> bit & 1)
                ;
            else
                mx += 1ll << bit; //, bug(bit);
            // bug(mx);
        }
    }
    else
    {
        for (auto [bit, has] : has_bit)
            if (mn >> bit & 1)
                mn -= 1ll << bit;
    }
    cout << mn << ' ' << mx << endl;
}

标签:integers,2025.1,16,int,cdot,1200,leq,ldots,color
From: https://www.cnblogs.com/jkkk/p/18677538

相关文章

  • 高级java每日一道面试题-2025年01月16日-框架篇[Mybatis篇]-说说Mybatis的缓存机制?
    如果有遗漏,评论区告诉我进行补充面试官:说说Mybatis的缓存机制?我回答:在Java高级面试中,MyBatis的缓存机制是一个重要的话题。MyBatis是一个流行的Java持久化框架,它提供了强大的数据库访问能力和灵活的SQL映射配置。为了提高查询性能并减少数据库访问次数,MyBatis引入了......
  • springboot基于Web的影像科智能信息挂管理系统_4a16y5e8
    收藏关注不迷路!!......
  • 【2025-01-16】帮同事买陈皮
    20:00爱是一颗星,一切迷途的船只,虽然不懂得天文,却要靠它引导。                                                 ——威廉·莎士比亚今天我让老家的高中同学给我寄了一......
  • 2025/1/16 实验作业——OSPF
    R1-3为区域0,R3-4为区域1,其中R3的环回在区域0:R3的0/0/0接口和环回在区域0,0/0/1接口在区域1R3为DR设备:R3的RIP值最大R4的环回不能宣告:要配缺省路由全网可达:全网通保证更新安全:进行手工认证减少路由条目:进行手工汇总192.168.1.0/24进行合理分配:此拓扑图中共有2个广播域和......
  • 学习疯狂JAVA讲义1.16
    练习结果:(如有更好方法,敬请指点)这两天沉迷刘晓庆自传—《人生不怕从头再来》,光看前言就入坑了,这女人身上的魅力是无与伦比的,她的经历是文坛作家们绞尽脑汁,想到死,想到吐血都编撰不出来的,既刺激又真实,让人不舍得睡醒再读,吸引着我必须当天读完!        金句摘抄如......
  • 2025.1.16 html
    写一个静态网页代码,分为三个区域,top区域有Login和Register;menu区域有treemenu;还有一个main区域。点击Login,Registe或treemenu会在main区域里显示相应的内容。''top.html页面代码'top.htmlLoginRegister'Login.html页面代码'PleaseLogInLogin:......
  • 2025年1月16日
    调整今天突然意识到自己翻蠢了你如果真的想往上走你就得狠得下心来说狠得下心就恨得下心你所有的事情都得靠你自己在你的上升道路上,对他人不能有一丝的同情不能有一丝的期待你有一丝的同情你就有了破绽你有了破绽他人就会利用这个破绽设局做你的局就是明面上看起来......
  • [2025.1.16 JavaSE学习]线程常用方法
    线程常用方法setName:设置线程名称getName:返回线程名称start:使线程开始执行,JVM底层调用该线程的start0()方法run:调用线程对象run方法setPriority:更改线程优先级,三个级别:getPriority:获取线程优先级sleep:线程休眠interrupt:中断线程,但并没有真正地结束线程(不是终止,是中断),......
  • 2025-1-12至16-uniapp初体验
    2025-1-12今天主要就是在熟悉app开发软件应用,发现它的页面开发起来跟我们的web是一样的,初始界面就跟VScode操作一样,毕竟第一步是要做页面,然后它的控制台跟tomcat集成之后使用很像,之后就是复习一下web的css。盒子模型:margin:外边距控制边框离屏幕的距离(top上,left左等)paddi......
  • 十分钟写作Day4 1.16
    前言本来昨天和赵北,南皓文和樊绍峰一起去看北京男篮德比,但又因昨天是命题作文,没有记录下我当时的感慨,便在今天的随笔里说说我的看法。正文与其说是感慨,不如说这是从不同角度观察这场比赛。由于赵北已经在他的随笔里介绍了比赛的全过程,因此我在这里也不过多的赘述比赛本身。而......