首页 > 其他分享 >TOYOTA SYSTEMS Programming Contest 2023(AtCoder Beginner Contest 330)

TOYOTA SYSTEMS Programming Contest 2023(AtCoder Beginner Contest 330)

时间:2023-11-26 13:44:38浏览次数:38  
标签:AtCoder Beginner Contest int ll cin ans rep

TOYOTA SYSTEMS Programming Contest 2023(AtCoder Beginner Contest 330)

A - Counting Passes

int main() {
    IOS;
    cin >> n >> m;
    int ans = 0;
    rep (i, 1, n) cin >> k, ans += k >= m;
    cout << ans;
    return 0;
}

B - Minimize Abs 1

int main() {
    IOS;
    int l, r; cin >> n >> l >> r;
    rep (i, 1, n) {
        cin >> m;
        int y = m;
        if (r <= m) y = r;
        else if (l >= m) y = l;
        cout << y << ' ';
    }
    return 0;
}

C - Minimize Abs 2

考虑枚举 x,然后通过开根号贪心找 y

int main() {
    IOS;
    long long x; cin >> x;
    ll ans = x;
    for (ll i = 0, ii = i * i; ; ++i, ii = i * i) {
        ll s = x - ii;
        ans = min(ans, abs(s));
        if (s <= 0) break;
        ll j = ceil(sqrt(s));
        ans = min(ans, abs(j * j + ii - x));
        ans = min(ans, abs((j - 1) * (j - 1) + ii - x));
        if (j <= i) break;
    }
    cout << ans;
    return 0;
}

D - Counting Ls

枚举三角形的中心点 A,然后去枚举同 X 轴的点 B,再枚举同 y 轴的点 C。

然后就是推公式,化简。

int main() {
    IOS;
    cin >> n;
    ll ans = 0, cnt = 0;
    vector<vector<int>> a(n);
    vector<int> b(n);
    rep (i, 0, n - 1) rep (j, 0, n - 1) {
        char c; cin >> c;
        if (c == 'o') a[i].pb(j), ++b[j];
    }
    rep (i, 0, n - 1) {
        int sz = a[i].size();
        int c = 0;
        for (auto &x : a[i]) c += b[x] - 1;
        ans += 1ll * c * (sz - 1);
    }
    cout << ans;
    return 0;
}

E - Mex and Update

线段树维护 MEX, 只需要维护 [0, 20000] 区间即可。

const int N = 2e5 + 5;

int n, m, _, k, cas;
int a[N];

struct BitTree {
    struct node { int l, r, val; } tr[N << 2];
    void push_up(int rt) {
        tr[rt].val = 0;
        if (tr[rt << 1].l == tr[rt << 1].r) tr[rt].val += tr[rt << 1].val > 0;
        else tr[rt].val += tr[rt << 1].val;

        if (tr[rt << 1 | 1].l == tr[rt << 1 | 1].r) tr[rt].val += tr[rt << 1 | 1].val > 0;
        else tr[rt].val += tr[rt << 1 | 1].val;
    }
    void build(int rt, int l, int r) {
        tr[rt] = {l, r, 0};
        if (l == r) { tr[rt].val = 0; return; }
        int mid = l + r >> 1;
        build(rt << 1, l, mid); build(rt << 1 | 1, mid + 1, r);
    }
    void change(int rt, int x, int k) {
        if (tr[rt].l == x && tr[rt].r == x) {
            tr[rt].val += k;
            return;
        }
        int mid = tr[rt].l + tr[rt].r >> 1;
        if (x <= mid) change(rt << 1, x, k);
        else change(rt << 1 | 1, x, k);
        push_up(rt);
    }
    int ask(int rt) {
        if (tr[rt].l == tr[rt].r) return tr[rt].l;
        if (tr[rt << 1].val < tr[rt << 1].r - tr[rt << 1].l + 1) return ask(rt << 1);
        return ask(rt << 1 | 1);
    }
} bit;

int main() {
    IOS;
    bit.build(1, 0, 200001);
    cin >> n >> m;
    rep (i, 1, n) {
        cin >> a[i];
        if (a[i] <= 200000)
            bit.change(1, a[i], 1);
    }
    rep (i, 1, m) {
        int x, y; cin >> x >> y;
        if (a[x] <= 200000) bit.change(1, a[x], -1);
        a[x] = y;
        if (a[x] <= 200000) bit.change(1, a[x], 1);
        cout << bit.ask(1) << '\n';
    }
    return 0;
}

F - Minimize Bounding Square

倍增,把 x 轴 y 轴分开处理即可

const int N = 2e5 + 5;

int n, m, _, cas;
ll k, sx[N], sy[N];
int x[N], y[N];

ll check(int d, ll s[], int a[]) {
    ll mi = 1ll << 60;
    rep (i, 2, n * 2 + 1) {
        int c = a[i >> 1] - (i & 1 ? d : 0);
        ll res = 0;
        int x = lower_bound(a + 1, a + 1 + n, c) - a - 1;
        res += 1ll * c * x - s[x];
        x = lower_bound(a + 1, a + 1 + n, c + d) - a - 1;
        res += s[n] - s[x] - 1ll * (c + d) * (n - x);
        umin(mi, res);
    }
    return mi;
}

int main() {
    IOS;
    cin >> n >> k;
    rep (i, 1, n) cin >> x[i] >> y[i];
    sort(x + 1, x + 1 + n); sort(y + 1, y + 1 + n);
    rep (i, 1, n) sx[i] = sx[i - 1] + x[i], sy[i] = sy[i - 1] + y[i];
    int ans = (1 << 30) - 1;
    per (i, 29, 0) if (check(ans - (1 << i), sx, x) + check(ans - (1 << i), sy, y) <= k)
        ans -= 1 << i;
    cout << ans;
    return 0;
}

标签:AtCoder,Beginner,Contest,int,ll,cin,ans,rep
From: https://www.cnblogs.com/2aptx4869/p/17856892.html

相关文章

  • AtCoder Beginner Contest 330
    A-CountingPasses(abc330A)题目大意给定\(n\)个学生的分数,以及及格分\(x\),问多少人及格了。解题思路依次判断即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_stdio(false);cin.ti......
  • The 2021 ICPC Asia Shenyang Regional Contest
    Preface合肥前的最后一场VP了,本来计划是我和祁神两个人打,但后面徐神还是来救场了然后这场我们过的最难的两题都是徐神切的,直接给我们抬进Au区了属于是而且徐神最后也差一点写出G(TLEon72),同时也一眼秒了D(没时间写了),看来这场让三个徐神来打感觉10题随便出线了A.ABiteofTey......
  • AtCoder Beginner Contest 329 F
    AtCoderBeginnerContest329FF-ColoredBall(atcoder.jp)(启发式合并)问题陈述有\(N\)个编号为\(1,2,\ldots,N\)的盒子。最初,盒子\(i\)中有一个颜色为\(C_i\)的小球。给你\(Q\)个查询,你要按顺序处理。每个查询都由一对整数\((a,b)\)给出,并要求您执行以下......
  • The 2021 ICPC Asia Nanjing Regional Contest (XXII Open Cup, Grand Prix of Nanjin
    Preface来场我最爱的SUA的题,而且恰逢南京站因此袋鼠题懂得都懂然而好家伙点开题目一看怎么全是OP题,我们队没一个玩原的这下大输特输了因此这场前中期可以说是崩完了,一个签到因为没判\(n=1\)从20min挂到150min,除此之外其它题目基本上都要挂上三四发不过好在最后20min连着过了卡......
  • AtCoder Regular Contest 144 E GCD of Path Weights
    洛谷传送门AtCoder传送门喵喵题。考虑若所有点权都已确定,如何求\(1\)到\(n\)所有路径权值和的\(\gcd\)。考虑如何check一个\(x\)是否合法。\(x\)合法的充要条件是,把不能从\(1\)到达的点和不能到达\(n\)的点扔掉后,存在一组\(\{f_n\}\),使得对于每条\(u\tov\)......
  • [AtCoder Toyota2023 Spring Final] Git Gud
    拜谢MagicDuck大神。其次我很喜欢洛谷逆天翻译把大翻译成小……首先考虑算一下贡献,考虑每个点的深度,一开始都是1,进行合并以后相当于首先把两个端点的深度累计到答案里,然后再选择一边给它的联通块内每个点深度增加1。那么容易发现我们可以算贡献转化为每个联通块权值为它向外......
  • AtCoder Beginner Contest 329
    劳累一天不该写题,启发式合并都写错了A-Spread(abc329A)题目大意给定一个字符串,将每个字符输出出来,中间留个空格。解题思路遍历输出即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_std......
  • AtCoder Beginner Contest(abc) 326
    B-326-likeNumbers难度:⭐题目大意如果一个三位数的百位和十位的乘积等于个位,那么这个数就是合法的;问大于等于n的最小的合法的数是多少;解题思路因为数据范围很小,所以可以直接暴力;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios......
  • AtCoder Beginner Contest 329
    C-Countxxx题意是:给你一个字符串,求出字符串里面相同字母的子串数量思路:用map映射即可,取每个字母的最大长度,然后加起来usingnamespacestd;intmain(){ intn; strings; cin>>n>>s; map<char,int>mp; intct=1; for(inti=1;i<n;i++){ if(s[i]!=s[i-1]){ mp[s[......
  • AtCoder Beginner Contest 329 (ABC329)
    A.Spread不说了,代码。B.Next不说了,代码。C.CountxxxDescription给定一个长度为\(N\)的字符串\(S\),求\(S\)中非空连续,并且包含重复字符的连续子串长度。例如$S=$aaabaa,则它满足上述条件子串为a,aa,aaa,b。Solution这道题\(1\leN\le2\times10^5\),显然......