It should be by far the easiest game. I did not have time to do the question to be completed.
Topic links: https://ac.nowcoder.com/acm/contest/884#question
A:
Note that the diameter of the tree can be virtual.
B:
Linear-based questions. Recent topics particularly linear multi-school groups.
C:
This question is 2018 Nanchang network game the original title (almost, the same approach can be had), topic Link: https://nanti.jisuanke.com/t/38228
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define init(a,b) fill(begin(a),end(a),b) 28 #define sot(a,b) sort(a+1,a+1+b) 29 #define rep1(i,a,b) for(int i=a;i<=b;++i) 30 #define rep0(i,a,b) for(int i=a;i<b;++i) 31 #define repa(i,a) for(auto &i:a) 32 #define eps 1e-8 33 #define int_inf 0x3f3f3f3f 34 #define ll_inf 0x7f7f7f7f7f7f7f7f 35 #define lson curPos<<1 36 #define rson curPos<<1|1 37 /* namespace */ 38 using namespace std; 39 /* header end */ 40 41 const int maxn = 3e6 + 10; 42 43 struct Node { 44 ll maxx, minn; 45 }; 46 47 struct SegT { 48 Node mem[maxn << 2]; 49 void build(ll *s, int curPos, int curL, int curR) { 50 if (curL == curR) { 51 mem[curPos].maxx = mem[curPos].minn = s[curL]; 52 return; 53 } 54 int mid = (curL + curR) >> 1; 55 build(s, lson, curL, mid); 56 build(s, rson, mid + 1, curR); 57 mem[curPos].maxx = max(mem[lson].maxx, mem[rson].maxx); 58 mem[curPos].minn = min(mem[lson].minn, mem[rson].minn); 59 } 60 61 ll queryMax(int curPos, int curL, int curR, int qL, int qR) { 62 if (qL <= curL && curR <= qR) 63 return mem[curPos].maxx; 64 int mid = (curL + curR) >> 1; 65 if (qR <= mid) return queryMax(lson, curL, mid, qL, qR); 66 else if (qL > mid) return queryMax(rson, mid + 1, curR, qL, qR); 67 else return max(queryMax(lson, curL, mid, qL, mid), queryMax(rson, mid + 1, curR, mid + 1, qR)); 68 } 69 70 ll queryMin(int curPos, int curL, int curR, int qL, int qR) { 71 if (qL <= curL && curR <= qR) 72 return mem[curPos].minn; 73 int mid = (curL + curR) >> 1; 74 if (qR <= mid) return queryMin(lson, curL, mid, qL, qR); 75 else if (qL > mid) return queryMin(rson, mid + 1, curR, qL, qR); 76 else return min(queryMin(lson, curL, mid, qL, mid), queryMin(rson, mid + 1, curR, mid + 1, qR)); 77 } 78 }; 79 SegT segT1, segT2; 80 int n, a[maxn], b[maxn], _b[maxn], l[maxn], r[maxn]; 81 ll ans = -1e18, s1[maxn], s2[maxn]; 82 83 void solve() { 84 stack<int>st; st.push(1); 85 l[1] = 1; 86 rep1(i, 2, n) { 87 while (!st.empty() && a[i] <= a[st.top()]) st.pop(); 88 if (st.empty()) l[i] = 1; 89 else l[i] = st.top() + 1; 90 st.push(i); 91 } 92 while (!st.empty()) st.pop(); 93 r[n] = n; st.push(n); 94 for (int i = n - 1; i >= 1; i--) { 95 while (!st.empty() && a[i] < a[st.top()]) st.pop(); 96 if (st.empty()) r[i] = n; 97 else r[i] = st.top() - 1; 98 st.push(i); 99 } 100 } 101 102 int main() { 103 scanf("%d", &n); 104 s1[0] = 0; s2[n + 1] = 0; 105 rep1(i, 1, n) scanf("%d", &a[i]); 106 rep1(i, 1, n) { 107 scanf("%d", &b[i]); _b[i] = b[i]; 108 s1[i] = s1[i - 1] + b[i]; 109 } 110 for (int i = n; i >= 1; i--) s2[i] = s2[i + 1] + b[i]; 111 segT1.build(s1, 1, 1, n); 112 segT2.build(s2, 1, 1, n); 113 solve(); 114 rep1(i, 1, n) { 115 ll maxl = segT2.queryMax(1, 1, n, l[i], i) - s2[i + 1]; 116 ll maxr = segT1.queryMax(1, 1, n, i, r[i]) - s1[i - 1]; 117 ll tmp = a[i] * (maxl + maxr - b[i]); 118 ans = max(ans, tmp); 119 maxl = segT2.queryMin(1, 1, n, l[i], i) - s2[i + 1]; 120 maxr = segT1.queryMin(1, 1, n, i, r[i]) - s1[i - 1]; 121 tmp = a[i] * (maxl + maxr - b[i]); 122 ans = max(ans, tmp); 123 } 124 printf("%lld\n", ans); 125 return 0; 126 }
D:
At that time I called table reading a few minutes, suddenly feeling a kind: For the solvability can not be divisible by the number n 3, only a certain number can or two out of it?
The answer is obvious. Discuss the classification result to the n% 3.
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 1e2 + 10; 21 int func[maxn]; 22 23 int main() { 24 int t; scanf("%d", &t); 25 while (t--) { 26 ll n; scanf("%lld", &n); 27 if (n % 3 == 0) { 28 printf("1 %lld\n", n); 29 continue; 30 } 31 ll cmp = n; 32 int cnt = 0; 33 while (cmp) { 34 func[++cnt] = cmp & 1; 35 cmp >>= 1; 36 } 37 rep0(i, 2, cnt) { 38 ll ans1 = 0, ans2 = 0; 39 for (int j = cnt; j >= i + 1; j--) ans1 = ans1 * 2 + func[j]; 40 for (int j = i; j >= 1; j--) ans2 = ans2 * 2 + func[j]; 41 rep1(j, 1, i) ans1 *= 2; 42 if (ans2 % 3 == 1) { 43 rep1(j, i + 1, cnt) 44 if (j % 2 == 0 && func[j]) { 45 ans2 |= (1ll << j - 1); 46 break; 47 } 48 int flag = 0; 49 if (ans2 % 3 != 0) 50 rep1(j, i + 1, cnt) 51 if (j % 2 == 1 && func[j]) { 52 if (!flag)flag = j; 53 else { 54 ans2 |= (1ll << flag - 1); ans2 |= (1ll << j - 1); 55 break; 56 } 57 } 58 } else if (ans2 % 3 == 2) { 59 rep1(j, i + 1, cnt) 60 if (j % 2 == 1 && func[j]) { 61 ans2 |= (1ll << j - 1); 62 break; 63 } 64 int flag = 0; 65 if (ans2 % 3 != 0) 66 rep1(j, i + 1, cnt) 67 if (j % 2 == 0 && func[j]) { 68 if (!flag)flag = j; 69 else { 70 ans2 |= (1ll << flag - 1); ans2 |= (1ll << j - 1); 71 break; 72 } 73 } 74 } 75 if (ans2 % 3 != 0)continue; 76 if (ans1 % 3 == 1) { 77 rep1(j, 1, i) 78 if (j % 2 == 0 && func[j]) { 79 ans1 |= (1ll << j - 1); 80 break; 81 } 82 int flag = 0; 83 if (ans2 % 3 != 0) 84 rep1(j, 1, i) 85 if (j % 2 == 1 && func[j]) { 86 if (!flag) flag = j; 87 else { 88 ans1 |= (1ll << flag - 1); ans1 |= (1ll << j - 1); 89 break; 90 } 91 } 92 } else if (ans1 % 3 == 2) { 93 rep1(j, 1, i) 94 if (j % 2 == 1 && func[j]) { 95 ans1 |= (1ll << j - 1); 96 break; 97 } 98 int flag = 0; 99 if (ans1 % 3 != 0) 100 rep1(j, 1, i) 101 if (j % 2 == 0 && func[j]) { 102 if (!flag) flag = j; 103 else { 104 ans1 |= (1ll << flag - 1); ans1 |= (1ll << j - 1); 105 break; 106 } 107 } 108 } 109 if (ans1 % 3 != 0)continue; if ((ans1 | ans2) != n)continue; 110 printf("2 %lld %lld\n", ans1, ans2); 111 break; 112 } 113 } 114 }
E:
dp。
F:
+ Segment tree balanced tree.
G:
Tree dp.
H:
Gaussian elimination math.
I:
String title. Generalized suffix automata.
J:
dp + shortest.
K:
Given a sequence of numbers, Q: How many sub-sequence of the digital sequence, its value can be divisible by 300.
1 #include<iostream> 2 #include<cstdio> 3 #include<vector> 4 5 6 using namespace std; 7 string s; 8 typedef long long ll; 9 const int maxn = 1e6; 10 int f[maxn][4]; 11 int p[maxn]; 12 int main() { 13 cin >> s; 14 int len = s.length(); 15 int suf = 0; 16 for (int i = len - 1; i >= 0; i--) { 17 if (i == len - 1) { 18 suf = s[i] - '0'; 19 } else { 20 suf = suf * 10 + s[i] - '0'; 21 } 22 suf %= 3; 23 p[i] = suf; 24 } 25 f[0][p[1]] ++; 26 for (int i = 0; i < len; i++) { 27 f[i][0] = f[i - 1][0]; 28 f[i][1] = f[i - 1][1]; 29 f[i][2] = f[i - 1][2]; 30 f[i][p[i]] ++; 31 } 32 ll tot = 0; 33 ll ans = 0; 34 for (int i = len - 1; i >= 0; i--) { 35 if (s[i] == '0') { 36 ans++; 37 if (i < len - 1 && s[i + 1] != '0') { 38 tot = 1ll; 39 } else { 40 tot++; 41 } 42 } 43 if (tot >= 2 && s[i] == '0' && i > 0 && s[i - 1] != '0') { 44 ans += (tot - 1) * tot / 2; 45 ans += (f[i][p[i]] - 1) * (tot - 1); 46 tot = 0; 47 } 48 } 49 if (tot >= 2) { 50 ans += (tot - 1) * tot / 2; 51 tot = 0 ; 52 } 53 cout << age << endl; 54 return 0 ; 55 }