2019icpc徐州网络赛

E. XKC’s basketball team

求大于等于 a i a_i ai的最右边的下标j,ans = j - i - 1。

#include <iostream>
#include <cstdio>

using namespace std;
typedef long long ll;
const int N = 5e5 + 50;

struct Node {
    int l, r;
    ll dat;
} tree[N << 2];

ll a[N], n, m;

inline void pushup(int p) {
    tree[p].dat = max(tree[p << 1].dat, tree[p << 1 | 1].dat);
}

void build(int p, int l, int r) {
    tree[p].l = l, tree[p].r = r;
    if (l == r) {
        tree[p].dat = a[l];
        return;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    pushup(p);
}

int ask(int p, int l, int r, ll w) {
    if (tree[p].l == tree[p].r) {
        return tree[p].l;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    if (r > mid && tree[p << 1 | 1].dat >= w) return ask(p << 1 | 1, l, r, w);
    else if (l <= mid && tree[p << 1].dat >= w) return ask(p << 1, l, r, w);
    else return -1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    build(1, 1, n);
    for (int i = 1; i <= n - 1; i++) {
        int ans = ask(1, i + 1, n, a[i] + m);
        if (ans == -1) cout << -1;
        else cout << ans - i - 1;
        cout << ' ';
    }
    cout << -1 << endl;
    return 0;
}

C. Buy WaterMelon

签到。

#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n&1 || n==2) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

D. Carneginon

模拟,签到。

#include<iostream>
using namespace std;
string t, s;

int main() {
    int q;
    cin >> t >> q;
    while (q--) {
        cin >> s;
        if (t.size() > s.size()) {
            if (t.find(s) != -1)
                cout << "my child!" << endl;
            else
                cout << "oh, child!" << endl;
        } else if (t.size() == s.size()) {
            if (t == s)
                cout << "jntm!" << endl;
            else
                cout << "friend!" << endl;
        } else {
            if (s.find(t) != -1)
                cout << "my teacher!" << endl;
            else
                cout << "senior!" << endl;
        }
    }
    return 0;
}

B. so easy

用map模拟并查集,初始时每个点的父亲指向父亲节点后面第一个可用点,当删除一个点i时,令x的父亲等于x+1的父亲。

#include <cstdio>
#include <map>
#include <unordered_map>

using namespace std;
unordered_map<int, int> fa;

int find(int x) {
    if (!fa.count(x)) return x;
    return fa[x] = find(fa[x]);
}
int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    int op, x;
    while (q--) {
        scanf("%d %d", &op, &x);
        if (op == 1) {
            fa[x] = find(x + 1);
        } else {
            int ans = find(x);
            if (ans > n) ans = -1;
            printf("%d\n", ans);
        }
    }
    return 0;
}

A. Who is the better?

中国剩余定理 + 斐波那契博弈
队里的学姐大佬一眼看出直接秒杀tql
中国剩余定理还不会
先放学姐代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
typedef __int128 ll;//头一次知道这么大的数
ll a1, m1, a2, m2;

ll exgcd(ll a, ll b, ll &x, ll &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll a[1005];
int cnt;

void init() {
    a[1] = 1, a[2] = 1;
    for (int i = 3; a[i - 1] <= 1e17; i++) {
        a[i] = a[i - 1] + a[i - 2];
        cnt = i;
    }
}

inline __int128 read() {
    int X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}

int main() {
    int q;
    ll n;
    init();
    cin >> q;
    int flag = 1;
    a1 = read();
    m1 = read();
    for (int i = 0; i < q - 1; i++) {
        a2 = read();
        m2 = read();
        ll k1, k2;
        ll d = exgcd(a1, a2, k1, k2);

        if ((m2 - m1) % d) {
            flag = 0;
        }
        ll t = a2 / d;
        k1 *= (m2 - m1) / d;
        k1 = (k1 % t + t) % t;
        m1 = k1 * a1 + m1;
        a1 = a1 / d * a2;
        if (a1 < 0)
            a1 = -a1;
    }
    if (!flag)
        cout << "Tankernb!" << endl;
    else {
        n = (m1 % a1 + a1) % a1;
        int flag = 0;
        for (int i = 1; i < cnt; i++)
            if (n == a[i]) {
                printf("Lbnb!\n");
                flag = 1;
                break;
            }
        if (!flag)
            printf("Zgxnb!\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值