codeforces Round 314 div.2 分类: codeforces introspect 2015-08-08 13:52 7人阅读 评论(0) 收藏
这次比赛是用小号打的,于是现在小号比大号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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。