比较简单的一场。
题目链接:https://codeforces.com/contest/1167
A:
手速快三分钟就切了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define pb push_back 4 #define mp make_pair 5 #define sot(a,b) sort(a+1,a+1+b) 6 #define rep(i,a,b) for (int i=a;i<=b;i++) 7 #define eps 1e-8 8 #define int_inf (1<<30)-1 9 #define ll_inf (1LL<<62)-1 10 #define lson curPos<<1 11 #define rson curPos<<1|1 12 13 using namespace std; 14 15 int t; 16 17 int main() 18 { 19 cin>>t; 20 while(t--){ 21 int n; string s; cin>>n>>s; 22 int flag=0; 23 for (int i=0;i<n-10;i++) if (s[i]=='8') flag=1; 24 if (flag) puts("YES"); else puts("NO"); 25 } 26 return 0; 27 }
B:
非常简单的一道交互。读入a[1]*a[2],a[2]*a[3],a[3]*a[4],a[4]*a[5]之后next_permutation枚举就完事了。
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 fir first 9 #define sec second 10 #define sot(a,b) sort(a+1,a+1+b) 11 #define rep1(i,a,b) for(int i=a;i<=b;++i) 12 #define rep0(i,a,b) for(int i=a;i<b;++i) 13 #define repa(i,a) for(auto &i:a) 14 #define eps 1e-8 15 #define int_inf 0x3f3f3f3f 16 #define ll_inf 0x7f7f7f7f7f7f7f7f 17 #define lson curPos<<1 18 #define rson curPos<<1|1 19 /* namespace */ 20 using namespace std; 21 /* header end */ 22 23 const int maxn = 6; 24 int a[maxn] = {4, 8, 15, 16, 23, 42}, b[6]; 25 26 int main() 27 { 28 rep0(i, 0, 4) 29 { 30 printf("? %d %d ", i + 1, i + 2); fflush(stdout); 31 scanf("%d", &b[i]); 32 } 33 do 34 { 35 if (a[0]*a[1] == b[0] && a[1]*a[2] == b[1] && a[2]*a[3] == b[2] && a[3]*a[4] == b[3]) 36 return printf("! %d %d %d %d %d %d ", a[0], a[1], a[2], a[3], a[4], a[5]), 0; 37 } while (next_permutation(a, a + 6)); 38 return 0; 39 }
C:
一眼数据结构题,DSU维护即可。
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 fir first 9 #define sec second 10 #define sot(a,b) sort(a+1,a+1+b) 11 #define rep1(i,a,b) for(int i=a;i<=b;++i) 12 #define rep0(i,a,b) for(int i=a;i<b;++i) 13 #define repa(i,a) for(auto &i:a) 14 #define eps 1e-8 15 #define int_inf 0x3f3f3f3f 16 #define ll_inf 0x7f7f7f7f7f7f7f7f 17 #define lson curPos<<1 18 #define rson curPos<<1|1 19 /* namespace */ 20 using namespace std; 21 /* header end */ 22 23 struct DSU: vector<int> 24 { 25 vector<int>size; 26 DSU(int n): vector<int>(n), size(n, 1) 27 { 28 rep0(i, 0, n) at(i) = i; 29 } 30 int find(int u) 31 { 32 return at(u) == u ? u : at(u) = find(at(u)); 33 } 34 void merge(int u, int v) 35 { 36 u = find(u), v = find(v); 37 if (u != v) 38 { 39 at(v) = u; 40 size[u] += size[v]; 41 } 42 } 43 }; 44 45 int n, m; 46 47 int main() 48 { 49 scanf("%d%d", &n, &m); 50 DSU dsu(n + 1); 51 rep1(i, 1, m) 52 { 53 int sum; scanf("%d", &sum); 54 if (sum) 55 { 56 int u; scanf("%d", &u); 57 rep0(j, 1, sum) 58 { 59 int v; scanf("%d", &v); dsu.merge(u, v); 60 } 61 } 62 } 63 rep1(i, 1, n) printf("%d ", dsu.size[dsu.find(i)]); 64 puts(""); 65 return 0; 66 }
D:
是个很简单的贪心,但是有非常巧妙的做法。
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 fir first 9 #define sec second 10 #define sot(a,b) sort(a+1,a+1+b) 11 #define rep1(i,a,b) for(int i=a;i<=b;++i) 12 #define rep0(i,a,b) for(int i=a;i<b;++i) 13 #define repa(i,a) for(auto &i:a) 14 #define eps 1e-8 15 #define int_inf 0x3f3f3f3f 16 #define ll_inf 0x7f7f7f7f7f7f7f7f 17 #define lson curPos<<1 18 #define rson curPos<<1|1 19 /* namespace */ 20 using namespace std; 21 /* header end */ 22 23 int n, x = 0, y = 0; 24 string s; 25 26 int main() 27 { 28 cin >> n >> s; 29 for (auto i : s) 30 if (i == '(') cout << x, x ^= 1; 31 else cout << y, y ^= 1; 32 cout << endl; 33 return 0; 34 }
E:
暂时没想到怎么做,应该是个数据结构题。
晚上看了胡老师代码才知道这是个数组乱搞题,是我蔡了。
1 //via yang12138 2 /* basic header */ 3 #include <bits/stdc++.h> 4 /* define */ 5 #define ll long long 6 #define dou double 7 #define pb emplace_back 8 #define mp make_pair 9 #define fir first 10 #define sec second 11 #define sot(a,b) sort(a+1,a+1+b) 12 #define rep1(i,a,b) for(int i=a;i<=b;++i) 13 #define rep0(i,a,b) for(int i=a;i<b;++i) 14 #define repa(i,a) for(auto &i:a) 15 #define eps 1e-8 16 #define int_inf 0x3f3f3f3f 17 #define ll_inf 0x7f7f7f7f7f7f7f7f 18 #define lson curPos<<1 19 #define rson curPos<<1|1 20 /* namespace */ 21 using namespace std; 22 /* header end */ 23 24 const int maxn = 1e6 + 10; 25 int n, x, l[maxn], r[maxn], a[maxn], pos[maxn]; //l[i],r[i]是i在数组中出现的最左最右位置 26 27 int main() 28 { 29 scanf("%d%d", &n, &x); 30 for (int i = 1; i <= x; i++) l[i] = n + 1, r[i] = 0; 31 for (int i = 1; i <= n; i++) 32 { 33 scanf("%d", &a[i]); 34 l[a[i]] = min(i, l[a[i]]); r[a[i]] = max(i, r[a[i]]); 35 } 36 int rpos = x, curL = n + 1, curR = 0; 37 while (rpos >= 1) 38 { 39 if (r[rpos] < curL) curL = min(curL, l[rpos--]); 40 else 41 { 42 rpos++; 43 break; 44 } 45 pos[rpos + 1] = curL; 46 } 47 if (!rpos) 48 return printf("%lld ", 1LL * x * (x + 1) / 2), 0; 49 ll ans = x - rpos + 2; 50 for (int i = 1; i <= x; i++) 51 { 52 curR = max(curR, r[i]); 53 while (curL <= curR) 54 { 55 rpos++; 56 if (rpos == x + 1) curL = n + 1; 57 else curL = pos[rpos]; 58 } 59 ans += x - rpos + 2; 60 if (l[i + 1] <= curR) break; 61 } 62 printf("%lld ", ans); 63 return 0; 64 }
tutorial std:
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int N = int(1e6) + 10; 6 int n, x; 7 int a[N]; 8 vector <int> pos[N]; //数字i出现过的所有位置 9 int prefMax[N]; //递增序列 10 11 int main() 12 { 13 scanf("%d %d", &n, &x); 14 for (int i = 0; i < n; ++i) 15 { 16 scanf("%d", a + i); 17 pos[a[i]].push_back(i); 18 prefMax[i] = max(a[i], (i > 0 ? prefMax[i - 1] : a[i])); 19 } 20 int p = 1, lst = n + 5; //lst是上一个数在数组出现的最左端的下标 21 for (int i = x; i >= 1; --i) 22 { 23 if (pos[i].empty()) //没出现过这个数 24 { 25 p = i; 26 continue; 27 } 28 if (pos[i].back() > lst) break; //不能有交错的区间 29 p = i; //p是符合条件的最小数字 30 lst = pos[i][0]; 31 } 32 long long ans = 0; 33 lst = -1; 34 for (int l = 1; l <= x; ++l) 35 { 36 int r = max(l, p - 1); //符合条件的最小数字和当前数字比较 37 if (lst != -1) r = max(r, prefMax[lst]); 38 ans += x - r + 1; 39 if (!pos[l].empty()) 40 { 41 if (pos[l][0] < lst) break; 42 lst = pos[l].back(); 43 } 44 } 45 cout << ans << endl; 46 return 0; 47 }
F:
可以线段树但没必要,树状数组秒杀。
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 fir first 9 #define sec second 10 #define sot(a,b) sort(a+1,a+1+b) 11 #define rep1(i,a,b) for(int i=a;i<=b;++i) 12 #define rep0(i,a,b) for(int i=a;i<b;++i) 13 #define repa(i,a) for(auto &i:a) 14 #define eps 1e-8 15 #define int_inf 0x3f3f3f3f 16 #define ll_inf 0x7f7f7f7f7f7f7f7f 17 #define lson curPos<<1 18 #define rson curPos<<1|1 19 /* namespace */ 20 using namespace std; 21 /* header end */ 22 23 const int mod = 1e9 + 7; 24 const int maxn = 5e5 + 10; 25 ll a[maxn], b[maxn], c[maxn], ans = 0; 26 int n; 27 28 void addmod(ll &a, ll b) 29 { 30 a += b; 31 if (a >= mod) a -= mod; 32 if (a < 0) a += mod; 33 } 34 35 void add(int u, int val) 36 { 37 for (; u <= n; u += u & -u) addmod(c[u], val); 38 } 39 40 ll sum(int u) 41 { 42 ll ret = 0; 43 for (; u > 0; u -= u & -u) addmod(ret, c[u]); 44 return ret; 45 } 46 47 int id(int x) 48 { 49 return lower_bound(b, b + n, x) - b + 1; 50 } 51 52 ll solve() 53 { 54 rep1(i, 1, n) c[i] = 0; 55 ll ans = 0; 56 rep0(i, 0, n) 57 { 58 ll curr = sum(id(a[i])); 59 addmod(ans, (a[i] * curr % mod) * (n - i) % mod); 60 add(id(a[i]), i + 1); 61 } 62 return ans; 63 } 64 65 int main() 66 { 67 scanf("%d", &n); 68 rep0(i, 0, n) scanf("%lld", &a[i]), b[i] = a[i]; 69 sort(b, b + n); 70 rep0(i, 0, n) 71 addmod(ans, a[i] * (i + 1) % mod * (n - i) % mod); 72 addmod(ans, solve()); 73 reverse(a, a + n); 74 addmod(ans, solve()); 75 printf("%lld ", ans); 76 return 0; 77 }
G:
才3个人过的题,再见。