2022.07.10 暑假集训 个人排位赛
Posted 晁棠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2022.07.10 暑假集训 个人排位赛相关的知识,希望对你有一定的参考价值。
2022.07.10 暑假集训 个人排位赛(五)
赛后反省
垫底了。两道思维题老是和自己错误的想法过不去,做题的时候还不够清醒。后面状态直接崩了。
Problem B
出处
HDU-5145
题解
不用莫队直接被卡常了。
莫队+组合数学。每次添加一个点的时候则表示要除以这个数出现的次数的阶乘。每次增添或删除的时候记录即可。
代码
// Good Good Study, Day Day AC.
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ffor(i,a,b) for(int i=(a) ;i<=(b) ;i++)
#define rrep(i,a,b) for(int i=(a) ;i>=(b) ;i--)
#define mst(v,s) memset(v,s,sizeof(v))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define INF 0x7f7f7f7f7f7f7f7f
#define inf 0x7f7f7f7f
#define PII pair<int,int>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e4 + 5;
int n, T = 1, m;
int a[N];
int cnt[N];
int power[N];
int len;
struct BBB
int l, r, id, flag;
int ans;
b[N];
void ready()
power[0] = 1;
ffor(i, 1, 30000)
power[i] = (ll)power[i - 1] * i % mod;
int t = 1;
int get_(int x)
return x / len;
bool cmp(BBB i, BBB j)
if (i.flag == j.flag) return i.r < j.r;
return i.flag < j.flag;
bool cmpid(BBB i, BBB j)
return i.id < j.id;
int qsm(int x, int y)
int res = 1;
while (y)
if (y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
return res;
void add(int x, int& res)
if (!cnt[x]) res++;
cnt[x]++;
t = t * cnt[x] % mod;
void del(int x, int& res)
t = t * qsm(cnt[x], mod - 2) % mod;
cnt[x]--;
if (!cnt[x]) res--;
void work()
cin >> n >> m;
len = sqrt(n);
ffor(i, 1, n)
cin >> a[i];
t = 1;
ffor(i, 1, m)
cin >> b[i].l >> b[i].r;
b[i].id = i;
b[i].flag = get_(b[i].l);
mst(cnt, 0);
sort(b + 1, b + m + 1, cmp);
for (int k = 1, i = 0, j = 1, res = 0; k <= m; k++)
int id = b[k].id, l = b[k].l, r = b[k].r;
while (i < r) add(a[++i], res);
while (i > r) del(a[i--], res);
while (j < l) del(a[j++], res);
while (j > l) add(a[--j], res);
b[k].ans = power[r - l + 1] * qsm(t, mod - 2) % mod;
sort(b + 1, b + m + 1, cmpid);
ffor(i, 1, m) cout << b[i].ans << '\\n';
signed main()
IOS;
ready();
cin >> T;
while (T--)
work();
return 0;
Problem E
出处
Codeforces-1301C
题解
思维构造题。将0的个数均等分在m+1个区间即可,也就是每个1之间(包括两边)都尽量有相等数量的0。这样子能保证能够贡献的0所贡献的值是最多的。
代码
// Good Good Study, Day Day AC.
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ffor(i,a,b) for(int i=(a) ;i<=(b) ;i++)
#define rrep(i,a,b) for(int i=(a) ;i>=(b) ;i--)
#define mst(v,s) memset(v,s,sizeof(v))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define INF 0x7f7f7f7f7f7f7f7f
#define inf 0x7f7f7f7f
#define PII pair<int,int>
#define int long long
using namespace std;
int n, T = 1;
void ready()
int get_(int x)
return x * (x + 1) / 2;
void work()
int m;
cin >> n >> m;
n = n - m;
int c1 = n % (m + 1);
int c2 = m + 1 - c1;
int n1 = n / (m + 1) + 1;
int n2 = n / (m + 1);
int ans = get_(n + m) - c1 * get_(n1) - c2 * get_(n2);
cout << ans << '\\n';
signed main()
IOS;
cin>>T;
while (T--)
ready();
work();
return 0;
Problem F
出处
Codeforces-1304C
题解
每次记录目前能够达到的区间。如果下一个客人的区间与现在的区间没有交集,即不可满足。
代码
// Good Good Study, Day Day AC.
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ffor(i,a,b) for(int i=(a) ;i<=(b) ;i++)
#define rrep(i,a,b) for(int i=(a) ;i>=(b) ;i--)
#define mst(v,s) memset(v,s,sizeof(v))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define INF 0x7f7f7f7f7f7f7f7f
#define inf 0x7f7f7f7f
#define PII pair<int,int>
#define int long long
using namespace std;
const int N = 105;
int n, T = 1;
struct FFF
int t, l, r;
a[N];
void ready()
bool cmp(FFF i, FFF j)
if (i.t == j.t)
return (i.r - i.l + 1) > (j.r - j.l + 1);
return i.t < j.t;
bool work()
int nx, ny;
cin >> n >> nx;
ny = nx;
ffor(i, 1, n) cin >> a[i].t >> a[i].l >> a[i].r;
// cout<<'\\n';
a[0].t = 0;
//sort(a + 1, a + n + 1, cmp);
ffor(i, 1, n)
int d = a[i].t - a[i - 1].t;
int lx = nx - d, ly = ny;
int rx = nx, ry = ny + d;
int x = lx, y = ry;
// cout<<nx<<' '<<ny<<'\\n';
// cout<<x<<' '<<y<<'\\n'<<'\\n';
if (y < a[i].l || a[i].r < x) return false;
//nx = max(x, a[i].l);
//ny = min(y, a[i].r);
//cout << x << ' ' << y << '\\n';
if (a[i].l <= x && y <= a[i].r)
nx = x; ny = y;
continue;
if (x <= a[i].l && a[i].r <= y)
nx = a[i].l; ny = a[i].r;
continue;
if (y >= a[i].l && y<a[i].r)
nx = a[i].l; ny = y;
continue;
if (a[i].r >= x)
nx = x; ny = a[i].r;
continue;
return true;
signed main()
IOS;
ready();
cin >> T;
while (T--)
if (work()) cout << "YES\\n";
else cout << "NO\\n";
return 0;
/*
2 -7
15 -5 4
20 1 8
*/
Problem G
出处
Codeforces-1301A
题解
同个位置上,c必须与a或b至少一个相同,则可以完成。
代码
// Good Good Study, Day Day AC.
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <deque>
#include &以上是关于2022.07.10 暑假集训 个人排位赛的主要内容,如果未能解决你的问题,请参考以下文章