A. Dora’s Set (思维)
题意:
DoraDoraDora有一个包含整数的集合 sss。一开始,她会将 KaTeX parse error: Undefined control sequence: \[ at position 1: \̲[̲l, r\]中的所有整数放入集合 sss。也就是说,整数 xxx最初会在集合中,当且仅当 l≤x≤rl \leq x \leq rl≤x≤r时。然后执行以下操作:
-
从集合 sss中选择三个不同的整数 aaa、 bbb和 ccc,使得 gcd(a,b)=gcd(b,c)=gcd(a,c)=1\gcd(a, b) = \gcd(b, c) = \gcd(a, c) = 1gcd(a,b)=gcd(b,c)=gcd(a,c)=1。
-
从集合 sss中删除这三个整数。
请问可以执行的最大操作数是多少?
分析:
我们考虑倒偶数彼此之间不互质。相邻的奇数是互质的,那么我们只需要统计出区间中奇数个数,两个一对凑对数,除以222即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int N = 3e5 + 10;
const int InF = 2e9 + 5;
const int mod = 998244353;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int l, r;
cin >> l >> r;
int ans;
if (l & 1)
{
ans = (r - l + 1 + 1) / 2;
}
else
{
ans = (r - l + 1) / 2;
}
ans /= 2;
cout << ans << endl;
}
return 0;
}
B. Index and Maximum Value (思维)
题意:
给出一个整数数组 a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_na_1,a_2,…,a_n按顺序执行 mmm个操作。每个操作都属于以下两种类型之一:
-
+ l r\texttt{+ l r}+ l r。给定两个整数 lll和 rrr,对于所有 1≤i≤n1 \leq i \leq n1≤i≤n且 l≤a_i≤rl \leq a\_i \leq rl≤a_i≤r,a_i:=a_i+1a\_i := a\_i + 1a_i:=a_i+1。
-
- l r\texttt{- l r}- l r。给定两个整数 lll和 rrr,对于所有 1≤i≤n1 \leq i \leq n1≤i≤n且 l≤a_i≤rl \leq a\_i \leq rl≤a_i≤r, a_i:=a_i−1a\_i := a\_i - 1a_i:=a_i−1。
例如,如果初始数组为 KaTeX parse error: Undefined control sequence: \[ at position 5: a = \̲[̲7, 1, 3, 4, 3\],执行操作 + 2 4\texttt{+} \space 2 \space 4+ 2 4后,数组变为 KaTeX parse error: Undefined control sequence: \[ at position 5: a = \̲[̲7, 1, 4, 5, 4\]。然后,执行操作 - 1 10\texttt{-} \space 1 \space 10- </

最低0.47元/天 解锁文章
1514

被折叠的 条评论
为什么被折叠?



