250804总结

· · 个人记录

模拟赛

100 + 100 + 100 + 100 + 60 = 460
自从有了E之后第一次一分没挂:)
第一次抢到首A:)
总榜第7,有E之后最高的一次:)
(但是怎么这么多AKer!这么多人做出来E!qwq我太菜了

A - 变回文

估分:100;实际得分:100
直接枚举在哪里插什么即可:)
因为插进去的只有可能是本来就有的字符,所以不需要枚举所有小写字母,枚举s就好了
估计出题人也是这么想的,所以第一次测的时候就没挂

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int T, n;
string s;

bool check (int i, char c) {
    string t = s.substr(1, i) + c + s.substr(i + 1, n - i);
    for (int i = 0; i <= n; i++) {
        if (t[i] != t[n - i]) return 0;
    }
    cout << t << "\n";
    return 1;
}

int main () {
    for (cin >> T; T--;) {
        cin >> s;
        n = s.size();
        s = ' ' + s;
        int get_ans = 0;
        for (int i = 0; i <= n && !get_ans; i++) {
            for (int j = 1; j <= n; j++) {
                if (check(i, s[j])) {
                    get_ans = 1;
                    break;
                }
            }
        }
        if (!get_ans) {
            cout << "NA\n";
        }
    }
    return 0;
}

B - 仪仗队

估分:100;实际得分:100
不是n为什么只有100,那我写O(nlogn)干啥呢…
把a和b都排个序,用双指针乱搞一下就完了,应该是比较典的题:)
被数据范围吓到了,想了10多分钟有没有bug

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n, m, a[110], b[110], ans;

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    for (int i = 1, j = 1; i <= n; i++) {
        for (; a[i] - b[j] > 1 && j <= m; j++);
        if (j > m) break;
        if (b[j] - a[i] > 1) continue;
        ans++;
        j++;
    }
    cout << ans;
    return 0;
}

C - x:y

估分:100;实际得分:100
今天最唐的做法就是我的了:)
不难发现,离散化之后就可以枚举d了,那怎么算分呢
很明显,可以排个序再用lower_bound乱搞,但我偏偏在想到这个之前想到了树状数组…我是奶龙,我才是奶龙qwq
然后赛后我又发现排了序之后根本就不需要离散化,d直接从a和b里面枚举就行了……这下更糖了:)
不过还好没挂分:)
考场写的树状数组屎山:

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n, m, a[200010], b[200010], c[400010], tr[400010][2], ansx, ansy;

int lb (int x) {
    return x & -x;
}

void add (int x, int y, int t) {
    for (; x <= n + m; x += lb(x)) {
        tr[x][t] += y;
    }
}

int query (int x, int t) {
    int ret = 0;
    for (; x; x -= lb(x)) {
        ret += tr[x][t];
    }
    return ret;
}

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        c[i] = a[i];
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        c[n + i] = b[i];
    }
    sort(c + 1, c + n + m + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = lower_bound(c + 1, c + n + m + 1, a[i]) - c;
        add(a[i], 1, 0);
    }
    for (int i = 1; i <= m; i++) {
        b[i] = lower_bound(c + 1, c + n + m + 1, b[i]) - c;
        add(b[i], 1, 1);
    }
    ansx = -1e9;
    for (int i = 1; i <= n + m; i++) {
        int tx = query(i - 1, 0), ty = query(i - 1, 1);
        int x = tx * 2 + (n - tx) * 3, y = ty * 2 + (m - ty) * 3;
        if (x - y > ansx - ansy || (x - y == ansx - ansy && x > ansx)) {
            ansx = x;
            ansy = y;
        }
    }
    cout << ansx << ':' << ansy;
    return 0;
}

wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb
wssb

D - 区间子串

估分:100;实际得分:100
喜提第一个首A:)
我也没想到我最菜的dp居然会是我的第一个首Aqwq
状态:f[i]表示从1到i,最后一个区间的右端点为i有多少种方案。
转移:先找到以i为右端点时最靠右的合法的左端点l,那么f[i] = \sum_{j = 1} ^ {l} f[j] \cdot (l - j),把括号拆开就可以写2个奇奇怪怪的前缀和实现O(1)转移。
初始化:f[0] = 1
屎山:

#include <bits/stdc++.h>
#define LL long long

using namespace std;

string s, t;
LL n, m, f[100010], qwq[100010], s1[100010], s2[100010], mod = 1e9 + 7;

int main () {
  cin >> s >> t;
  n = s.size(); m = t.size();
  s = ' ' + s;
  for (int i = 1; i <= n - m + 1; i++) {
    if (s.substr(i, m) == t) {
      qwq[i + m - 1] = 1;
    }
  }
  LL tmp = -1;
  f[0] = s2[0] = 1;
  s1[0] = n;
  for (int i = 1; i <= n; i++) {
    if (qwq[i]) {
      tmp = i - m;
    }
    if (tmp == -1) {
      f[i] = 0;
      s2[i] = s2[i - 1];
      s1[i] = s1[i - 1];
      continue;
    }
    f[i] = s1[tmp] - ((s2[tmp] * (n - tmp - 1)) % mod);
    f[i] += mod;
    f[i] %= mod;
    s1[i] = s1[i - 1] + f[i] * (n - i) % mod;
    s1[i] %= mod;
    s2[i] = s2[i - 1] + f[i];
    s2[i] %= mod;
  }
  cout << (s2[n] - 1 + mod) % mod;
    return 0;
}

E - 宝石展览

估分:60;实际得分:60
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
我数学太菜了
怎么过这题的这么多,我用2h都写不出来qwq
式子都写出来了,就是没想到二项式定理qwqwqwq
看完题解发现我就是世界上最傻的sb qwq
所以就写了一个60分的暴力:)
感谢出题人,暴力都有这么多分:)

#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL n, a[200010], v[200010], ans, mod = 1e9 + 7, f[1010], sum;

LL qpow (LL x, LL y) {
  LL ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) {
      (ret *= x) %= mod;
    }
    (x *= x) %= mod;
  }
  return ret;
}

int main () {
  cin >> n;
  int ff = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    if (a[i] > 1000) ff = 0;
  }
  if (ff) {
    f[0] = 1;
    for (int i = 1; i <= 1000; i++) {
      f[i] = f[i - 1] * i % mod;
    }
    for (int i = 1; i <= n; i++) {
      cin >> v[i];
      LL tmp = 1;
      for (int j = 1; j <= a[i]; j++) {
        tmp *= v[i];
        tmp %= mod;
        ans += tmp * f[a[i]] % mod * qpow(f[a[i] - j], mod - 2) % mod * qpow(f[j], mod - 2) % mod * qpow(2, sum - a[i]) % mod;
        ans %= mod;
      }
    }
    cout << ans;
  }
  return 0;
}

我天呐这居然是B队的T1,B队到底都是什么神仙qwq

字典树

好多题跟字典树都没啥关系
后来才知道AB都是从D队进口的:)
怎么模拟赛和题单都有别的队的题:)

A - Uninteresting Number

写了10分钟,一遍过:)
我要去D队了qwq
因为9的倍数代表它的各个数位上的数字之和是9的倍数,然后不难发现只有把2和3平方才有用,所以统计出2和3的个数,乱搞一下就好了

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int t;
string n;

int main () {
    for (cin >> t; t--;) {
        cin >> n;
        int s2 = 0, s6 = 0, s = 0;
        for (int i = 0; i < n.size(); i++) {
            s += n[i] - '0';
            s %= 9;
            if (n[i] == '2') {
                s2++;
            } else if (n[i] == '3') {
                s6++;
            }
        }
        for (; s % 3 != 0 && s2; s += 2, s2--);
        if (s % 3 != 0) {
            cout << "NO\n";
            continue;
        }
        s6 += s2 / 3;
        for (; s % 9 != 0 && s6; s += 6, s6--);
        if (s % 9 != 0) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }
    return 0;
}

B - String Typing

写了30分钟,WA两发
枚举在哪里复制即可。
WA是因为读错题qwq

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n;
string s;

int main () {
    cin >> n >> s;
    s = ' ' + s;
    int ans = n;
    for (int j = 2; j * 2 <= n; j++) {
        if (s.substr(1, j) == s.substr(j + 1, j)) {
            ans = min(ans, n - j + 1);
        }
    }
    cout << ans;
    return 0;
}

C - Essentially Different Suffixes

写了6分钟,一遍过
字典树板子题,按后缀建完树之后数有几个节点即可

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int n, tr[300010][30], ans, cnt;

void add (string s) {
    int k = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        int c = s[i] - 'a';
        if (!tr[k][c]) {
            tr[k][c] = ++cnt;
            ans++;
        }
        k = tr[k][c];
    }
}

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        add(s);
    }
    cout << ans;
    return 0;
}

E - Collapsing Strings

写了36分钟,MLE一发
按前缀建树然后用后缀累加答案
MLE是因为数组开大了qwq

#include <bits/stdc++.h>
#define LL long long

using namespace std;

LL n, cnt, tr[1000010][26], ans, sum[1000010][3];
string s[1000010];

void add (string s) {
    int k = 0;
    for (int i = 0; i < s.size(); i++) {
        int c = s[i] - 'a';
        if (!tr[k][c]) {
            tr[k][c] = ++cnt;
        }
        k = tr[k][c];
        sum[k][0] += s.size() - i;
        sum[k][1]++;
    }
    sum[k][2]++;
}

LL query (string s) {
    int k = 0;
    LL ret = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        int c = s[i] - 'a';
        for (int j = 0; j < 26; j++) {
            if (j == c) continue;
            if (!tr[k][j]) continue;
            ret += sum[tr[k][j]][0] + sum[tr[k][j]][1] * (i + 1);
        }
        if (tr[k][c]) {
            k = tr[k][c];
            ret += sum[k][2] * i;
        } else {
            k = 0;
            break;
        }
    }
    return ret + sum[k][0] - sum[k][1];
}

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        add(s[i]);
    }
    for (int i = 1; i <= n; i++) {
        ans += query(s[i]);
    }
    cout << ans;
    return 0;
}

写完总结叻:)好耶:)