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 <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;
string a,b,c;


void ready()
{

}


bool work()
{
    cin>>a>>b>>c;
    int len=a.size();
    ffor(i,0,len-1){
        if(c[i]!=a[i] && c[i]!=b[i])
            return false;
    }
    return true;
}

signed main()
{
	IOS;
    ready();
	cin>>T;
	while (T--) {
		if(work()) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值