11.23 周六
1.2025.2.19——1500
2.11.23 周六
3.11.24 周日4.11.25 周一日常5.2024.11.26 周二日常6.2024.11.27 周三7.2024.11.28周四8.2024.11.29 周五9.2024.11.30 周六10.2024.12.1 周日11.2024.12.2 周一12.2024.12.3 周二13.2024.12.4 周三14.2024.12.5 周四15.2024.12.7 周六16.2024.12.8 周日17.2024.12.9 周一18.2024.12.10 周二19.2024.12.11 周三20.2024.12.12 周四21.2024.12.13 周五22.2024.12.14 周六23.2024.12.16 周一24.2024.12.17 周二25.2024.12.18 周三26.2024.12.19 周四27.2024.12.20 周五28.2024.12.21 周六29.2024.12.22 周日30.2024.12.23 周一31.2024.12.24 周四32.2024.12.25 周三33.2024.12.26 周四34.2024.12.27 周五35.2024.12.28 周六36.2024.12.29 周日37.2024.12.30 周一38.2025.1.5——120039.2025.1.12——120040.2025.1.14——120041.2025.1.15——120042.2025.1.16——120043.2025.1.17——120044.2025.1.18——130045.2025.1.19——130046.2025.1.20——130047.2025.1.21——130048.2025.1.22——130049.2025.1.24——140050.2025.1.26——140051.2025.2.8——140052.2025.2.9——140053.2025.2.10——140054.2025.2.14——140055.2025.2.15——140056.2025.2.17——1400codeforces
Q1.1200 将一个序列分为若干集合,每个集合的和在一个区间内,问集合数量的最大值。
Q2.1400 长度为n的数组产生n-2个相邻三元组,问恰有1个元素不同的三元组的配对数。
Q3.1500 给定n个数组,设f(x)=max{任意次将x放入任意数组:x=mex{x,a[i]}},问f(0)+...+f(m)。(m<=1e9)
A1.前缀+二分:对于每个数作为起点二分找到满足条件的最左侧的数 细节较多。
双指针贪心 设s为维护的区间和 s<lim_l r++; s>lim_r l++。
A2.map+容斥:cnt_ab+cnt_ac+cnt_bc-3*cnt_abc 。
A3.结论:计算出每个数组的x1,x2关键点,设max_w=max(x1,x2),发现f(i)为max(i,max_w)。
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
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int n, L, R;
cin >> n >> L >> R;
vector<int> a(n + 1), pre(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i], pre[i] = pre[i - 1] + a[i];
int res = 0;
for (int st = 1; st <= n; st++)
{
if (a[st] > R)
continue;
if (a[st] >= L)
{
res++;
continue;
}
int l = st, r = n + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (pre[mid] - pre[st - 1] >= L)
r = mid;
else
l = mid;
}
if (r > n)
continue;
if (pre[r] - pre[st - 1] > R)
continue;
// bug2(st, r);
res++;
st = r;
}
cout << res << 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
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1);
map<pair<int, int>, int> cnt_ab, cnt_ac, cnt_bc;
map<tuple<int, int, int>, int> cnt_abc;
int res = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (i < 3)
continue;
res += cnt_ab[{a[i - 2], a[i - 1]}];
res += cnt_ac[{a[i - 2], a[i]}];
res += cnt_bc[{a[i - 1], a[i]}];
res -= 3 * cnt_abc[{a[i - 2], a[i - 1], a[i]}];
cnt_ab[{a[i - 2], a[i - 1]}]++;
cnt_ac[{a[i - 2], a[i]}]++;
cnt_bc[{a[i - 1], a[i]}]++;
cnt_abc[{a[i - 2], a[i - 1], a[i]}]++;
}
cout << res << endl;
}
A3.
#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
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
int max_w = 0;
for (int i = 0; i < n; i++)
{
int k;
cin >> k;
map<int, bool> has;
while (k--)
{
int x;
cin >> x;
has[x] = 1;
}
int find = 0;
for (int h = 0;; h++)
if (!has[h])
{
max_w = max(max_w, h);
find++;
if (find == 2)
break;
}
}
// bug(max_w);
int res = (m + 1) * max_w;
if (m > max_w)
res = (max_w + 1) * max_w + (max_w + 1 + m) * (m - max_w) / 2;
cout << res << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!