codeforces Round 314 div.2
来源:互联网 发布:淘宝论坛帐号 编辑:程序博客网 时间:2024/06/05 10:53
这次比赛是用小号打的,于是现在小号比大号rating高。。。QwQ
A题和B题很简单不多说。
C题:统计子序列中长度为3,公比为
从后往前处理,分别统计满足条件长度为1,2,3的序列的个数,
然而,当时只判断了 a[i]*k<=a[max] ,而没有判断 a[i]*k>=a[min] (k可能为负数), 所以FST了。。。
const int maxn = 2e5 + 5, size = maxn*3;int n, k, a[maxn];long long ans;int cnt[maxn], p[maxn], pl;long long f[maxn], g[maxn];int main(){#ifndef ONLINE_JUDGE freopen("C.in","r",stdin); freopen("C.out","w",stdout);#endif read(n), read(k); for(int i = 1; i <= n; i++) read(a[i]), p[i] = a[i]; std::sort(p + 1, p + n + 1); pl = std::unique(p + 1, p + n + 1) - (p + 1); for(int i = n; i > 0; i--) { int t = std::lower_bound(p + 1, p + pl + 1, a[i]) - p; if((long long)a[i]*k <= p[pl] && (long long)a[i]*k >= p[1]) { int v = std::lower_bound(p + 1, p + pl + 1, a[i]*k) - p; if(a[i]*k == p[v]) g[t] += f[v], f[t] += cnt[v]; } cnt[t]++; } for(int i = 1; i <= pl; i++) ans += g[i]; write(ans);#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
D题:从结束状态逆向处理,用并查集维护最长区间,直到满足可放船数>=实际船数才得到答案。
const int maxn = 2e5 + 5, maxk = maxn;int n, k, a, m;int x[maxk], cnt;bool e[maxn];int fa[maxn], size[maxn];int find(int x){ return (x == fa[x])?x:(fa[x] = find(fa[x]));}void gather(int x,int y){ if(x > y) std::swap(x, y); x = find(x), y = find(y), fa[y] = x; if(x != y) size[x] += size[y], size[y] = 0;}void init(){ read(n), read(k), read(a), read(m); for(int i = 1; i <= m; i++) read(x[i]), e[x[i]] = true;}void prework(){ for(int i = 1; i <= n; i++) fa[i] = i, size[i] = 1; for(int i = 1; i <= n; i++) if(i > 1 && !e[i] && !e[i-1]) gather(i, i - 1); for(int i = 1; i <= n; i++) if(fa[i] == i && !e[i]) cnt += (size[i]+1)/(a+1); }int solve(){ if(cnt >= k) return -1; for(int i = m; i >= 1; i--) { if(x[i] > 1 && !e[x[i]-1]) { cnt -= (size[find(x[i]-1)]+1)/(a+1); gather(x[i] - 1, x[i]); } if(x[i] < n && !e[x[i]+1]) { cnt -= (size[find(x[i]+1)]+1)/(a+1); gather(x[i], x[i] + 1); } cnt += (size[find(x[i])]+1)/(a+1); e[x[i]] = false; if(cnt >= k) return i; } return 0;}int main(){#ifndef ONLINE_JUDGE freopen("D.in","r",stdin); freopen("D.out","w",stdout);#endif init(), prework(); write(solve());#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
0 0
- codeforces Round 314 div.2
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #125 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #127 (Div. 2)
- Codeforces Round #127 (Div. 2)
- 聊天式对话框布局问题match_parent和layout_gravity那些事(android点点滴滴)
- QT仿酷狗
- 浅析Android Context
- iOS UITableView数据刷新
- STL hdu1540 Tunnel Warfare
- codeforces Round 314 div.2
- 什么是Windows服务
- 关于IO的同步,异步,阻塞,非阻塞
- 百度开放云java+tomcat部署web项目-小皇帝詹姆斯
- Data Structure 初学链表(ADT实现)
- 算术符优先级
- strcpy与memcpy的区别
- 2015.08.07网络编程read()函数详解
- 在winpe里头集成virtio驱动