2017-10-19校内训练题题解

T1

找规律发现点 a 的父亲是 aafib。(伪)lca。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define N 101
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drp(i, a, b) for (int i = a; i >= b; i--)
#define fech(i, x) for (int i = 0; i < x.size(); i++)
#define ll long long
#define abs(x) ((x) < 0 ? -(x) : (x))

inline ll read() {
    ll x = 0, flag = 1; char ch = getchar();
    while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
    while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * flag;
}
inline void write(ll x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }

const ll fib[] = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946,
17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903,
2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445,
225851433717, 365435296162, 591286729879, 956722026041, 1548008755920};

int find(ll x) {
    int l = 1, r = 59, ans;
    while (l <= r) {
        int mid = l + r >> 1;
        if (fib[mid] < x) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}

int main() {
    int m = read();
    while (m--) {
        ll a = read(), b = read();
        if (a == b) { printf("%lld\n", a); continue; }
        if (abs(a - b) <= 1) { puts("1"); continue; }
        if (a == 1 || b == 1) { puts("1"); continue; }
        while (a != b) {
            if (a < b) swap(a, b);
            a -= fib[find(a)];
        }
        write(a), puts("");
    }
    return 0;
}

T2

代码解释一切系列。

#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define N 300001
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drp(i, a, b) for (int i = a; i >= b; i--)
#define fech(i, x) for (int i = 0; i < x.size(); i++)
#define ll long long

inline int read() {
    int x = 0, flag = 1; char ch = getchar();
    while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
    while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * flag;
}
inline void write(int x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }

int n;
int a[N];
vector<int> bur[N];

int main() {
    cin >> n; int m = read();
    rep(i, 1, n) a[i] = read(), bur[a[i]].push_back(i);
    while (m--) {
        int op = read();
        if (op == 1) {
            int l = read(), r = read(), c = read();
            write((int)(upper_bound(bur[c].begin(), bur[c].end(), r) - lower_bound(bur[c].begin(), bur[c].end(), l)));
            puts("");
        }
        else {
            int x = read();
            if (a[x] == a[x + 1]) continue;
            (*lower_bound(bur[a[x]].begin(), bur[a[x]].end(), x))++;
            (*lower_bound(bur[a[x + 1]].begin(), bur[a[x + 1]].end(), x + 1))--;
            swap(a[x], a[x + 1]);
        }
    }
    return 0;
}

T3

但口胡,调不出来啊。调好了再写。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值