T2 纯诈骗,$m > 28$ 直接输出 $0$,我还写的 $m > 1000$。

异或(xor)

期望分数 $[60, 100]$,实际分数 $100$。

嗯,三角形怎么正宗二维差分啊。

既然 $y$ 是随着 $x$ 动的,那就对于每一次询问枚举每一行进行差分。第 $x$ 行需要把第 $[c,\ \min(n,\ x - r + c)]$ 个元素加上 $s$。对应差分数组 $d_{i, c}$ 加上 $s$,$d_{i, \min(n,\ i - r + c) + 1}$ 减去 $s$。

时间复杂度 $\mathcal{O}(nq)$,但因为三角形跑不满,所以最多大概是 $1.5 \times 10^8$(很悬),Linux 和 VJ 均过。

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int kMaxN = 1e3 + 10;

ll n, q, a[kMaxN][kMaxN], ans;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  freopen("xor.in", "r", stdin);
  freopen("xor.out", "w", stdout);
  cin >> n >> q;
  for (ll r, c, l, s; q; -- q) {
    cin >> r >> c >> l >> s;
    for (int i = r; i < min(n + 1, r + l); ++ i) {
      a[i][c] += s, a[i][min(n, i - r + c) + 1] -= s;
    }
  }
  for (int i = 1; i <= n; ++ i) {
    for (int j = 1; j <= n; ++ j) {
      a[i][j] += a[i][j - 1];
      ans ^= a[i][j];
    }
  }
  cout << ans << '\n';
  return 0; 
}

游戏(game)

期望分数 $[40, 80]$,实际分数 $88$ 变 $64$。改数据了啊啊啊。

赛时思路:分段得分。首先是 $\mathcal{O}(mn)$ 伪贪心,针对于 $m \le 1000$,Alice 操作时就看消除哪一部分($b_i$ 倍数或非 $b_i$ 倍数)减少的值大就消除哪一边,Bob 则相反。显然这个贪心方法是错的,因为仅考虑了当前这一局,未考虑全局最优,但作者太菜也写不出什么正确贪心。对于 $m > 1000$,直接输出 $0$,因为无论怎么拿都会被拿走。

正确思路:实际上,当 $m > 28$(即 $2 \cdot \max \log n$)时就可以全部被拿走。因为对于先手来说,如果他选择集合大小更小的,那么每一次集合大小至少减半。由于是轮流操作,所以要乘上 $2$。由于剩下的情况 $m \le 28$,Dfs 乱搞即可。

赛时代码:

#include <bits/stdc++.h>
 
using namespace std;

using ll = long long;
using ull = unsigned long long;

const int kMaxN = 2e5 + 20;

ll n, m, a[kMaxN], b[kMaxN], ans;
bool vis[kMaxN];

ll C1(ll x) {
  ll res = 0;
  for (int i = 1; i <= n; ++ i) {
    if (!vis[i] && !(a[i] % b[x])) {
      res += a[i];
    }
  } 
  return res;
}

ll C2(ll x) {
  ll res = 0;
  for (int i = 1; i <= n; ++ i) {
    if (!vis[i] && (a[i] % b[x])) {
      res += a[i];
    }
  } 
  return res;
}

void S1(ll x) {
  for (int i = 1; i <= n; ++ i) {
    if (!vis[i] && !(a[i] % b[x])) {
      vis[i] = 1;
    }
  }
}

void S2(ll x) {
  for (int i = 1; i <= n; ++ i) {
    if (!vis[i] && (a[i] % b[x])) {
      vis[i] = 1;
    }
  }
}

int main() {
  freopen("game.in", "r", stdin);
  freopen("game.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++ i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++ i) {
    cin >> b[i];
  }
  if (m > 1000) {
    return cout << "0\n", 0;
  }
  for (ll i = 1, x, y; i <= m; ++ i) {
    x = C1(i), y = C2(i);
    if (i % 2) {
      if (x > y) {
        S1(i);
      } else {
        S2(i);
      }
    } else {
      if (x > y) {
        S2(i);
      } else {
        S1(i);
      }
    }
  }
  for (int i = 1; i <= n; ++ i) {
    ans += (!vis[i]) * a[i];
  }
  cout << ans << '\n';
  return 0;
}

正确代码:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int kMaxN = 2e5 + 20;

ll n, m, a[kMaxN], b[kMaxN];
vector<ll> v;

ll Dfs(vector<ll> v, ll x){
  ll ans = 0;
  if (!v.size() || x > m){
    for (auto i : v) {
      ans += i;
    }
    return ans;
  }
  vector<ll> v2;
  for (auto i : v){
    if (!(i % b[x])) {
      v2.push_back(i);
    }
  }
  ans = Dfs(v2, x + 1);
  v2.clear();
  for (auto i : v){
    if (i % b[x]) {
      v2.push_back(i);
    }
  }
  if (x % 2) {
    return min(ans, Dfs(v2, x + 1));
  } else {
    return max(ans, Dfs(v2, x + 1));
  }
}

int main() {
  freopen("game.in", "r", stdin);
  freopen("game.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++ i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++ i) {
    cin >> b[i];
  }
  if (m > 28) {
    return cout << "0\n", 0;
  }
  for (int i = 1; i <= n; ++ i) {
    v.push_back(a[i]);
  }
  cout << Dfs(v, 1) << '\n';
  return 0; 
}

连通块(connect)

期望分数 $40$,实际分数 $40$。

暴力,先 $\mathcal{O}(n^2)$ 暴力建边。然后枚举删除哪个点,跑 Tarjan,也不知道为什么当时要跑 Tarjan。时间复杂度 $\mathcal{O}(Tnm)$。

#include <bits/stdc++.h>
 
using namespace std;

using ll = long long;
using ull = unsigned long long;

const int kMaxN = 1e5 + 10;

ll n, a[kMaxN], mn, ans, tim, low[kMaxN], dfn[kMaxN], col[kMaxN], scc, sccw[kMaxN];
bool p[kMaxN * 100], vis[kMaxN];
vector<int> e[kMaxN]; 
bool is[kMaxN], st[kMaxN];
stack<int> s;

void Tarjan(int x, int bid) {
  s.push(x);
  dfn[x] = low[x] = ++ tim;
  is[x] = 1;
  for (auto i : e[x]) {
    if (i == bid) {
      continue;
    }
    if (!dfn[i]) {
      Tarjan(i, bid);
      low[x] = min(low[x], low[i]);
    } else if (is[i]) {
      low[x] = min(low[x], dfn[i]);
    }
  }
  if (dfn[x] == low[x]) {
    ++ scc;
    for (int v; s.size(); ) {
      v = s.top();
      s.pop();
      is[v] = 0;
      ++ sccw[scc];
      if (x == v) {
        break;
      }
    }
  }
}

int main() {
  freopen("connect.in", "r", stdin);
  freopen("connect.out", "w", stdout); 
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  fill(p, p + (int)1e7 + 1, 1), p[0] = p[1] = 0;
  for (int i = 2; i <= 1e7; ++ i) {
    if (p[i]) {
      for (int j = i * 2; j <= 1e7; j += i) {
        p[j] = 0;
      }
    }
  }
  p[1] = 1;
  int t;
  for (cin >> t; t; -- t) {
    cin >> n, mn = 9e18;
    for (int i = 1; i <= n; ++ i) {
      e[i].clear();
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++ i) {
      for (int j = i + 1; j <= n; ++ j) {
        if (!p[__gcd(a[i], a[j])]) {
          e[i].push_back(j);
          e[j].push_back(i);
        }
      }
    }
    for (int i = 1; i <= n; ++ i) {
      ans = scc = tim = 0;
      fill(dfn + 1, dfn + n + 1, 0);
      fill(low + 1, low + n + 1, 0);
      fill(is + 1, is + n + 1, 0);
      fill(sccw + 1, sccw + n + 1, 0);
      for (int j = 1; j <= n; ++ j) {
        if (!dfn[j]) {
          Tarjan(j, i);
        }
      }
      for (int j = 1; j <= scc; ++ j) {
        ans = max(ans, sccw[j]);
      }
      mn = min(mn, ans);
    }
    cout << mn << '\n';
  }
  return 0;
}

公交路线(route)