#include<bits/stdc++.h> intmain(){ int a,b,c,d; std::cin >> a >> b >> c >> d; if(c >= a && d >= a) { std::cout << c << "-Y " << d << "-Y\n"; std::cout << "huan ying ru guan\n"; } elseif(c >= b || d >= b) { std::cout << c << "-Y " << d << "-Y\n"; if(c >= b) std::cout << "qing 1 zhao gu hao 2\n"; else std::cout << "qing 2 zhao gu hao 1\n"; } else { if(c > a) { std::cout << c << "-Y " << d << "-N\n"; std::cout << "1: huan ying ru guan\n"; } elseif(d > a) { std::cout << c << "-N " << d << "-Y\n"; std::cout << "2: huan ying ru guan\n"; } else { std::cout << c << "-N " << d << "-N\n"; std::cout << "zhang da zai lai ba\n"; } } return0; }
L1-4
小学数学题
1 2 3 4 5 6 7 8 9 10
#include<bits/stdc++.h> intmain(){ int a,b; std::cin >> a >> b; int ans = 1; for(int i = 1; i <= a + b; i++) ans = ans * i; std::cout << ans <<'\n'; return0; }
#include<bits/stdc++.h> constint MAXN = 2e5; int n,m,tim; std::vector<std::vector<int>> To,Fa; std::vector<int> Deep,dfn,id; voidinit(){ To.resize(MAXN + 1); Fa.resize(MAXN + 1,std::vector<int> (21)); Deep.resize(MAXN + 1); dfn.resize(MAXN + 1); id.resize(MAXN + 1); } voiddfs(int u){ dfn[u] = ++tim; id[tim] = u; Deep[u] = Deep[Fa[u][0]] + 1; for(int v : To[u]) { Fa[v][0] = u; dfs(v); } } intLca(int x,int y){ if(Deep[x] < Deep[y]) std::swap(x,y); for(int i = 20; i >= 0; i--) if(Deep[Fa[x][i]] >= Deep[y]) x = Fa[x][i]; if(x == y) return x; for(int i = 20; i >= 0; i--) if(Fa[x][i] != Fa[y][i]) { x = Fa[x][i]; y = Fa[y][i]; } return Fa[x][0]; } intdist(int x,int y){ int lca = Lca(x,y); return Deep[x] + Deep[y] - 2 * Deep[lca]; } intmain(){ std::cin >> n >> m; init(); for(int i = 1; i <= n; i++) { int x; std::cin >> x; if(x == -1) continue; To[x].push_back(i); } dfs(1); for(int k = 1; k <= 20; k++) for(int i = 1; i <= n; i++) Fa[i][k] = Fa[Fa[i][k - 1]][k - 1]; std::vector<int> ans(MAXN + 1),add(MAXN + 1),cnt(MAXN + 1); for(int i = 1; i <= m; i++) { std::cin >> add[i]; cnt[add[i]]++; } std::vector<int> nxt(MAXN + 1),pre(MAXN + 1); std::priority_queue<int> A,B; A.push(1); int pos = 1; for(int i = 2; i <= n; i++) { if(cnt[id[i]]) { A.push(Deep[id[i]]); nxt[pos] = id[i]; pre[id[i]] = pos; pos = id[i]; } } nxt[pos] = 1;pre[1] = pos; int ANS = 0; pos = 1; while(true) { ANS += dist(pos,nxt[pos]); if(nxt[pos] == 1) break; pos = nxt[pos]; }
for(int i = m; i >= 1; i--) { ans[i] = ANS - (A.top() - 1); cnt[add[i]]--; if(cnt[add[i]] == 0) { int x = add[i]; int l = pre[x]; int r = nxt[x]; ANS = ANS - dist(l,x) - dist(x,r) + dist(l,r); B.push(Deep[x]); nxt[l] = r; pre[r] = l; } while(!B.empty() && B.top() == A.top()) { B.pop(); A.pop(); } }
for(int i = 1; i <= m; i++) { std::cout << ans[i] << '\n'; } return0; }