• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# 2021,6,10 xjzx 模拟考试

5小时前 3次浏览

pts: 100

T1: 100

T2: 0

T3: 0

## T1

### Strategy

• (attack_i) 的代价主动进攻，此技能最多用 (k)
• (define_i) 的代价防御，此技能可以用无数次
• 和该敌人结盟，此技能只能用一次

(n leq 4000)

solution

std 复杂度 (O(n^2log~n)) ? ?

code

``````namespace Ariel_{
struct node{int id, num;}E[N];
bool cmp(node a, node b) {return a.num < b.num;}
int n, k, a[N], d[N], sum, Ans, p, o;
void main(){
for (int i = 1; i <= n; i++) a[i] = read(), d[i] = read(), sum += a[i];
for (int i = 1; i <= n; i++) E[i].num = d[i] - a[i], E[i].id = i;
sort (E + 1, E + n + 1, cmp);
for (int i = 1; i <= n; i++) {
Ans = sum - a[i], p = 1, o = 1;
while (o < n - k) {
if (E[p].id != i) Ans += E[p].num, o++;
p++;
}
while (p <= n) {
if (E[p].id != i)
if (E[p].num < 0) Ans += E[p].num;
else break;
p++;
}
printf("%lld ", Ans);
}
}
}
``````

## T2

### easy LCA

(nleq 6*10^5)

(solution)

(l_i) 表示 (nxtLCA_{a_i, a_{i + 1}})

``````namespace STACK{
stack<int> s;
//计算左边界
void calc_L(){
for (int i = 1; i < n; i++){
while(!s.empty() && l[s.top()] >= l[i])  R[s.top()] = i - 1, s.pop();
s.push(i);
}
while(!s.empty()) R[s.top()] = n - 1, s.pop();
}
//计算右边界
void calc_R(){
for (int i = n - 1; i >= 1; i--){
while(!s.empty() && l[i] < l[s.top()]) L[s.top()] = i + 1, s.pop();//左边界
s.push(i);
}
while(!s.empty()) L[s.top()] = 1, s.pop();//多余的情况
}
}
``````

code

(LCA) 用树剖写滴，可能有点长 emm

``````/*
work by:Ariel_
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stack>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1200010;
int x = 0,f = 1; char c = getchar();
while(c < '0'||c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c - '0'; c = getchar();}
return x*f;
}
int n, l[N], a[N], dep[N];
int L[N], R[N];
struct edge {int v, nxt;}e[N];
void add_edge(int u, int v) {
e[++cnt] = (edge){v, head[u]};
}
namespace LCA{
int fa[N], top[N], siz[N], son[N];
void dfs(int x, int f) {
fa[x] = f, siz[x] = 1, dep[x] = dep[f] + 1;
for (int i = head[x]; i; i = e[i].nxt) {
int v = e[i].v;
if(v == f) continue;
dfs(v, x);siz[x] += siz[v];
if(siz[v] > siz[son[x]]) son[x] = v;
}
}
void dfs2(int x, int tp) {
top[x] = tp;
if(son[x]) dfs2(son[x], tp);
for (int i = head[x]; i; i = e[i].nxt) {
int v = e[i].v;
if (v == fa[x] || v == son[x]) continue;
dfs2(v, v);
}
}
int lca(int x, int y){
while(top[x] != top[y]) {
if(dep[top[x]] < dep[top[y]]) swap(x, y);
x = fa[top[x]];
}
if(dep[x] > dep[y]) swap(x, y);
return x;
}
}
namespace STACK{
stack<int> s;
void calc_L(){
for (int i = 1; i < n; i++){
while(!s.empty() && l[s.top()] >= l[i])  R[s.top()] = i - 1, s.pop();
s.push(i);
}
while(!s.empty()) R[s.top()] = n - 1, s.pop();
}
void calc_R(){
for (int i = n - 1; i >= 1; i--){
while(!s.empty() && l[i] < l[s.top()]) L[s.top()] = i + 1, s.pop();//左边界
s.push(i);
}
while(!s.empty()) L[s.top()] = 1, s.pop();//多余的情况
}
}
namespace Ariel_{
int ans = 0;
void main() {
for (int i = 1, u, v; i < n; i++){
}
for (int i = 1; i <= n; i++) a[i] = read();
LCA::dfs(1, 0), LCA::dfs2(1, 1);
for (int i = 1; i < n; i++) l[i] = dep[LCA::lca(a[i], a[i + 1])];
STACK::calc_L(), STACK::calc_R();
for(int i = 1; i < n; i++) ans += (i - L[i] + 1) * (R[i] - i + 1) * l[i];
for(int i = 1; i <= n; i++) ans += dep[a[i]];
printf("%lld", ans);
}
}
signed main(){
Ariel_::main();
return 0;
}
``````

## T3

### Sc++arborough Fair

(n) 个点和 (m)无向边组成的图 (由于集市中存在桥，故不保证是平面图)，其中第 (i) 条道路连接 (u_i) ,(v_i) 两点，有 (w_i) 的概率是不能通行的。

(W) 定义一张图的不方便程度为图中的联通块个数，现在给定集市的地图，小 (W) 希望你能帮他求出这张图的期望不方便程度

(nleq 17)

solution