F题没出,J题没出,锅++
题目链接:https://ac.nowcoder.com/acm/contest/883#question
A:
神仙题。
B:
签到题。一眼可以二分长度。
1 /* basic header */ 2 #include3 /* 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;i11 #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 = 1e5 + 10; 21 int n, a[maxn], b[maxn], cnt1 = 0, cnt2 = 0; 22 23 int check(int x) { 24 x*=2; 25 rep1(i, x, n) 26 if (a[i] - a[i - x] == b[i] - b[i - x]) return 1; 27 return 0; 28 } 29 30 int main() { 31 a[0] = b[0] = 0; 32 scanf("%d", &n); 33 rep1(i, 1, n) { 34 int x; scanf("%1d", &x); 35 a[i] = a[i - 1], b[i] = b[i - 1]; 36 if (x) cnt1++, a[i]++; 37 else cnt2++, b[i]++; 38 } 39 int l = 1, r = n / 2; 40 while (l <= r) { 41 int mid = l + r >> 1; 42 if (check(mid)) l = mid + 1; 43 else r = mid - 1; 44 } 45 printf("%d %d\n", 2 * r, 2 * min(cnt1, cnt2)); 46 return 0; 47 }
不过队友O(n)前缀和过了。
1 #include2 #include 3 #include
C:
题解说是很有趣的构造题。
D:
数论。
E:
kruskal重构树神仙题。
F:
数据结构乱搞题。手写队列ac,优先队列似乎会TLE。
1 /* basic header */ 2 #include3 /* 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;i11 #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 = 5e2 + 10; 21 int n, m, a[maxn][maxn], maxx[maxn], minn[maxn], q[maxn][2]; 22 23 int main() { 24 int t; scanf("%d", &t); 25 while (t--) { 26 int ans = 1; 27 scanf("%d%d", &n, &m); 28 rep1(i, 1, n) { 29 rep1(j, 1, n) scanf("%d", &a[i][j]); 30 } 31 rep1(i, 1, n) { 32 rep1(j, 1, n) maxx[j] = -int_inf, minn[j] = int_inf; 33 rep1(j, i, n) { 34 // 维护第p列的极值 35 rep1(p, 1, n) maxx[p] = max(maxx[p], a[j][p]); 36 rep1(p, 1, n) minn[p] = min(minn[p], a[j][p]); 37 int l = 1, h0 = 0, h1 = 0, t0 = 1, t1 = 1; 38 rep1(r, 1, n) { 39 while (t0 <= h0 && maxx[r] >= maxx[q[h0][0]]) h0--; 40 while (t1 <= h1 && minn[r] <= minn[q[h1][1]]) h1--; 41 q[++h0][0] = q[++h1][1] = r; 42 while (l <= r && maxx[q[t0][0]] - minn[q[t1][1]] > m) { 43 l++; 44 if (q[t0][0] < l) t0++; 45 if (q[t1][1] < l) t1++; 46 } 47 ans = max(ans, (r - l + 1) * (j - i + 1)); 48 } 49 } 50 } 51 printf("%d\n", ans); 52 } 53 return 0; 54 }
G:
分治题。
H:
选一个超远的点,然后二分斜率求叉积判断即可。
1 #include2 #include 3 #include 4 #include 5 #include 6 #include
I:
dp。
J:
数据结构大暴力。
1 /* basic header */ 2 #include3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define sot(a,b) sort(a+1,a+1+b) 8 #define rep1(i,a,b) for(int i=a;i<=b;++i) 9 #define rep0(i,a,b) for(int i=a;i10 #define eps 1e-8 11 #define int_inf 0x3f3f3f3f 12 #define ll_inf 0x7f7f7f7f7f7f7f7f 13 #define lson (curpos<<1) 14 #define rson (curpos<<1|1) 15 /* namespace */ 16 using namespace std; 17 /* header end */ 18 19 const int maxn = 1e6 + 10; 20 unordered_map<string, int>mp; 21 int q, m; 22 char rs[maxn]; 23 24 struct _List { 25 string s[maxn]; 26 int pre[maxn], nxt[maxn], v[maxn]; 27 int sz, csz, head, tail; 28 29 void init() { 30 sz = 2, csz = 0, head = 1, tail = 2; 31 pre[head] = 0, nxt[head] = 2; 32 pre[tail] = 1, nxt[tail] = 0; 33 } 34 int app(string _s, int _v) { 35 csz++; 36 if (csz == m + 1) del(nxt[head]); 37 s[++sz] = _s, v[sz] = _v; 38 nxt[pre[tail]] = sz; 39 pre[sz] = pre[tail]; 40 nxt[sz] = tail; 41 pre[tail] = sz; 42 return sz; 43 } 44 void del(int pos) { 45 --csz; 46 mp.erase(s[pos]); 47 pre[nxt[pos]] = pre[pos]; 48 nxt[pre[pos]] = nxt[pos]; 49 } 50 } _list; 51 52 int main() { 53 int t; scanf("%d", &t); 54 while (t--) { 55 scanf("%d%d", &q, &m); 56 _list.init(); 57 mp.clear(); 58 rep1(i, 1, q) { 59 int op, v, pos; scanf("%d%s%d", &op, rs, &v); 60 string s(rs); 61 if (!op) { 62 if (mp.find(s) != mp.end()) { 63 pos = mp[s]; 64 v = _list.v[pos]; 65 _list.del(pos); 66 } 67 mp[s] = _list.app(s, v); 68 printf("%d\n", v); 69 } else { 70 int flag = 0; 71 if (mp.find(s) != mp.end()) { 72 pos = mp[s]; 73 flag = 1; 74 if (v == -1) { 75 pos = _list.pre[pos]; 76 if (pos == _list.head) flag = 0; 77 } else if (v == 1) { 78 pos = _list.nxt[pos]; 79 if (pos == _list.tail) flag = 0; 80 } 81 } 82 if (flag) printf("%d\n", _list.v[pos]); 83 else puts("Invalid"); 84 } 85 } 86 } 87 return 0; 88 }