2025.1.18——1300

news/2025/1/20 14:20:19/

2025.1.18——1300


A 1300

There are n n n cities located on the number line, the i i i-th city is in the point a i a_i ai. The coordinates of the cities are given in ascending order, so a 1 < a 2 < ⋯ < a n a_1 < a_2 < \dots < a_n a1<a2<<an.

The distance between two cities x x x and y y y is equal to ∣ a x − a y ∣ |a_x - a_y| axay.

For each city i i i, let’s define the closest city j j j as the city such that the distance between i i i and j j j is not greater than the distance between i i i and each other city k k k. For example, if the cities are located in points [ 0 , 8 , 12 , 15 , 20 ] [0, 8, 12, 15, 20] [0,8,12,15,20], then:

  • the closest city to the city 1 1 1 is the city 2 2 2;
  • the closest city to the city 2 2 2 is the city 3 3 3;
  • the closest city to the city 3 3 3 is the city 4 4 4;
  • the closest city to the city 4 4 4 is the city 3 3 3;
  • the closest city to the city 5 5 5 is the city 4 4 4.

The cities are located in such a way that for every city, the closest city is unique. For example, it is impossible for the cities to be situated in points [ 1 , 2 , 3 ] [1, 2, 3] [1,2,3], since this would mean that the city 2 2 2 has two closest cities ( 1 1 1 and 3 3 3, both having distance 1 1 1).

You can travel between cities. Suppose you are currently in the city x x x. Then you can perform one of the following actions:

  • travel to any other city y y y, paying ∣ a x − a y ∣ |a_x - a_y| axay coins;
  • travel to the city which is the closest to x x x, paying 1 1 1 coin.

You are given m m m queries. In each query, you will be given two cities, and you have to calculate the minimum number of coins you have to spend to travel from one city to the other city.
Input

The first line contains one integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

Each test case is given in the following format:

  • the first line contains one integer n n n ( 2 ≤ n ≤ 1 0 5 2 \le n \le 10^5 2n105);
  • the second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an ( 0 ≤ a 1 < a 2 < ⋯ < a n ≤ 1 0 9 0 \le a_1 < a_2 < \dots < a_n \le 10^9 0a1<a2<<an109);
  • the third line contains one integer m m m ( 1 ≤ m ≤ 1 0 5 1 \le m \le 10^5 1m105);
  • then m m m lines follow; the i i i-th of them contains two integers x i x_i xi and y i y_i yi ( 1 ≤ x i , y i ≤ n 1 \le x_i, y_i \le n 1xi,yin; x i ≠ y i x_i \ne y_i xi=yi), denoting that in the i i i-th query, you have to calculate the minimum number of coins you have to spend to travel from the city x i x_i xi to the city y i y_i yi.

Additional constraints on the input:

  • in every test case, for each city, the closest city is determined uniquely;
  • the sum of n n n over all test cases does not exceed 1 0 5 10^5 105;
  • the sum of m m m over all test cases does not exceed 1 0 5 10^5 105.

B 1300

In this problem, you are initially given an empty multiset. You have to process two types of queries:

  1. ADD x x x — add an element equal to 2 x 2^{x} 2x to the multiset;
  2. GET w w w — say whether it is possible to take the sum of some subset of the current multiset and get a value equal to w w w.
    Input

The first line contains one integer m m m ( 1 ≤ m ≤ 1 0 5 1 \le m \le 10^5 1m105) — the number of queries.

Then m m m lines follow, each of which contains two integers t i t_i ti, v i v_i vi, denoting the i i i-th query. If t i = 1 t_i = 1 ti=1, then the i i i-th query is ADD v i v_i vi ( 0 ≤ v i ≤ 29 0 \le v_i \le 29 0vi29). If t i = 2 t_i = 2 ti=2, then the i i i-th query is GET v i v_i vi ( 0 ≤ v i ≤ 1 0 9 0 \le v_i \le 10^9 0vi109).


C 1300

You are given an integer array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an, all its elements are distinct.

First, you are asked to insert one more integer a n + 1 a_{n+1} an+1 into this array. a n + 1 a_{n+1} an+1 should not be equal to any of a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an.

Then, you will have to make all elements of the array equal. At the start, you choose a positive integer x x x ( x > 0 x > 0 x>0). In one operation, you add x x x to exactly one element of the array. Note that x x x is the same for all operations.

What’s the smallest number of operations it can take you to make all elements equal, after you choose a n + 1 a_{n+1} an+1 and x x x?
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of testcases.

The first line of each testcase contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105).

The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an ( − 1 0 9 ≤ a i ≤ 1 0 9 -10^9 \le a_i \le 10^9 109ai109). All a i a_i ai are distinct.

The sum of n n n over all testcases doesn’t exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.


D 1300

Vlad found an array a a a of n n n integers and decided to sort it in non-decreasing order.

To do this, Vlad can apply the following operation any number of times:

  • Extract the first element of the array and insert it at the end;
  • Swap that element with the previous one until it becomes the first or until it becomes strictly greater than the previous one.

Note that both actions are part of the operation, and for one operation, you must apply both actions.

For example, if you apply the operation to the array [ 4 , 3 , 1 , 2 , 6 , 4 4, 3, 1, 2, 6, 4 4,3,1,2,6,4], it will change as follows:

  • [ 4 , 3 , 1 , 2 , 6 , 4 \color{red}{4}, 3, 1, 2, 6, 4 4,3,1,2,6,4];
  • [ 3 , 1 , 2 , 6 , 4 , 4 3, 1, 2, 6, 4, \color{red}{4} 3,1,2,6,4,4];
  • [ 3 , 1 , 2 , 6 , 4 , 4 3, 1, 2, 6, \color{red}{4}, 4 3,1,2,6,4,4];
  • [ 3 , 1 , 2 , 4 , 6 , 4 3, 1, 2, \color{red}{4}, 6, 4 3,1,2,4,6,4].

Vlad doesn’t have time to perform all the operations, so he asks you to determine the minimum number of operations required to sort the array or report that it is impossible.


E 1300

Yarik has already chosen n n n notes that he wants to use in his new melody. However, since their integers can be very large, he has written them down as an array a a a of length n n n, then the note i i i is b i = 2 a i b_i = 2^{a_i} bi=2ai. The integers in array a a a can be repeated.

The melody will consist of several combinations of two notes. Yarik was wondering how many pairs of notes b i , b j b_i, b_j bi,bj ( i < j ) (i < j) (i<j) exist such that the combination ( b i , b j ) (b_i, b_j) (bi,bj) is equal to the combination ( b j , b i ) (b_j, b_i) (bj,bi). In other words, he wants to count the number of pairs ( i , j ) (i, j) (i,j) ( i < j ) (i < j) (i<j) such that b i b j = b j b i b_i^{b_j} = b_j^{b_i} bibj=bjbi. Help him find the number of such pairs.
Input

The first line of the input contains one integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The first line of each test case contains one integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \leq n \leq 2 \cdot 10^5 1n2105) — the length of the arrays.

The next line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1 \leq a_i \leq 10^9 1ai109) — array a a a.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.


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

  • 前缀维护信息+二进制/充分性+数学+发现结论+配对优化


A

  1. 前缀维护信息,区间询问。
  2. 思考点是如何计算前缀。

B

  1. 充分性:判断是否可以组成时,枚举每一位进行判断。
  2. 思考点是判断某位是否可以被组成。

C

  1. 将一数组元素任意加某一确定数,致所有数相同。加的数为所有数 g c d gcd gcd 操作次数最少。
  2. 之前做过类似的题,但想不到为什么这样思考。自己数学推一下就想明白了。
  3. 至于 a [ i + 1 ] a[i+1] a[i+1] ,一开始出了假思路 a [ n ] + g / a [ n ] − g a[n]+g /a[n]-g a[n]+g/a[n]g 。实际最大值减某个倍数的最大公约数才是最优解。

D

  1. 模拟一下,观察发现结论即可。

E

  1. 除了相同的情况,二进制数中仅有24==42,统计对数,维护信息扫一遍即可。

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

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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;cin >> n;vector<int> a(n + 1);for (int i = 1; i <= n; i++)cin >> a[i];vector<int> pre(n + 1), suf(n + 2);auto closest = [&](int u, int r, int l){return abs(a[u] - a[r]) <= abs(a[u] - a[l]);};for (int i = 2; i <= n; i++){pre[i] = a[i] - a[i - 1];if (i == 2 || closest(i - 1, i, i - 2))pre[i] = 1;pre[i] += pre[i - 1];}for (int i = n - 1; i; i--){suf[i] = a[i + 1] - a[i];if (i == n - 1 || closest(i + 1, i, i + 2))suf[i] = 1;suf[i] += suf[i + 1];}// bugv(pre, 1);int q;cin >> q;while (q--){int st, ed;cin >> st >> ed;int res = pre[ed] - pre[st];if (st > ed)res = suf[ed] - suf[st];cout << res << endl;}
}

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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 q;cin >> q;vector<int> x(32);while (q--){int op, v;cin >> op >> v;if (op == 1)x[v]++;else{auto t = x;bool f = 1;for (int i = 0; v >> i; i++)if (v >> i & 1){int ned = 1, j = i;for (int j = i; ned && j >= 0; j--, ned <<= 1){int has = min(t[j], ned);t[j] -= has, ned -= has;}if (ned)f = 0;}cout << (f ? "YES" : "NO") << endl;}}
}

C

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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;cin >> n;vector<int> a(n + 1);for (int i = 1; i <= n; i++)cin >> a[i], a[i] += 1e9;sort(a.begin() + 1, a.end());int g = 0;for (int i = 2; i <= n; i++)g = __gcd(g, a[i] - a[i - 1]);if (!g)g = 1;map<int, bool> has;for (int i = 1; i <= n; i++)has[a[i]] = 1;for (int st = a[n] - g;; st -= g)if (!has[st]){a[0] = st;break;}int res = 0;for (auto v : a)res += (a[n] - v) / g;cout << res << endl;
}
// void _()
// {
//     int n;
//     cin >> n;
//     vector<int> a(n + 1);
//     for (int i = 1; i <= n; i++)
//         cin >> a[i], a[i] += 1e9;
//     sort(a.begin() + 1, a.end());
//     int g = 0;
//     for (int i = 2; i <= n; i++)
//         g = __gcd(g, a[i] - a[i - 1]);
//     if (!g)
//         g = 1;
//     bool f = 1;
//     for (int i = 1; i <= n; i++)
//         if (a[i] == a[n] - g)
//             f = 0;
//     a[0] = f ? a[n] - g : a[n] + g;
//     int mx = max(a[0], a[n]);
//     int res = 0;
//     for (auto v : a)
//         res += (mx - v) / g;
//     cout << res << endl;
// }

D

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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;cin >> n;vector<int> a(n);int mn = 1e10, id = -1;for (int i = 0; i < n; i++){int &x = a[i];cin >> x;if (x < mn)mn = x, id = i;}bool f = 1;for (int i = id + 1; i < n; i++)if (a[i] < a[i - 1])f = 0;cout << (f ? id : -1) << endl;
}

E

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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;cin >> n;int res = 0;map<int, int> cnt;while (n--){int x;cin >> x;res += cnt[x];if (x == 1)res += cnt[2];if (x == 2)res += cnt[1];cnt[x]++;}cout << res << endl;
}


http://www.ppmy.cn/news/1564672.html

相关文章

浅谈 JVM

JVM 内存划分 JVM 内存划分为 四个区域&#xff0c;分别为 程序计数器、元数据区、栈、堆 程序计数器是记录当前指令执行到哪个地址 元数据区存储存储的是当前类加载好的数据&#xff0c;包括常量池和类对象的信息&#xff0c;.java 编译之后产生 .class 文件&#xff0c;运…

【springboot 集成 mybatis-plus】

springboot 集成 mybatis-plus 前言实战代码生成器自动填充字段 前言 正如MyBatis-Plus官网所说&#xff0c;MyBatis-Plus 是一个 MyBatis 的增强工具&#xff0c;提供了强大的CRUD操作&#xff0c;支持主键自动生成&#xff0c;代码生成器&#xff0c;自动填充字段等等&#…

【ComfyUI专栏】ComfyUI的环境配置

对于常规的用户来说,我们碰到需要非常注意的问题,就是我们的ComfyUI的各个节点可能会有不兼容的情况,因此我们最好建立独立的Python虚拟环境。如何建立虚拟的环境呢?其实非常简单。 执行的命令如下: Python -m venv venv #创建Venv名称的虚拟环境 cd venv #进入到Venv …

InVideo AI技术浅析(四):机器学习

一、视频剪辑与合成 1. 工作原理 视频剪辑与合成是视频编辑中的核心任务,旨在将多个视频片段、音频和字幕等元素组合成一个连贯且富有吸引力的视频。InVideo AI 使用机器学习技术自动化这一过程,通过分析视频内容、识别重要片段并进行智能剪辑和合成。其核心目标是提升观众…

【Linux系统编程】—— 深度解析进程等待与终止:系统高效运行的关键

文章目录 进程创建再次认识fork()函数fork()函数返回值 写时拷贝fork常规⽤法以及调用失败的原因 进程终⽌进程终止对应的三种情况进程常⻅退出⽅法_exit函数exit函数return退出 进程等待进程等待的必要性进程等待的⽅法 进程创建 再次认识fork()函数 fork函数初识&#xff1…

人脸识别【python-基于OpenCV】

1. 导入并显示图片 #导入模块 import cv2 as cv#读取图片 imgcv.imread(img/wx(1).jpg) #路径名为全英文&#xff0c;出现中文 图片加载失败,"D:\picture\wx.jpg" #显示图片 &#xff08;显示标题&#xff0c;显示图片对象&#xff09; cv.imshow(read_picture,im…

【AI论文】迈向大型语言模型(LLM)训练开放数据集的最佳实践

摘要&#xff1a;许多人工智能公司未经版权所有者许可&#xff0c;就在其数据上训练大型语言模型&#xff08;LLM&#xff09;。这一行为的合法性因司法管辖区而异&#xff1a;在欧盟和日本等国家&#xff0c;这种行为在特定限制下是被允许的&#xff0c;而在美国&#xff0c;法…

vue3+vite+ts+router4+Pinia+Axios+sass 从0到1搭建

1、使用vite构建项目 npm create vitelatest 填写项目名的时候不能大写 2、跑起来之后配置下 import { defineConfig } from vite import vue from vitejs/plugin-vue import { resolve } from path // https://vite.dev/config/ export default defineConfig({plugins: [vue…