Educational Codeforces Round 41
Educational Codeforces Round 41
D. Pair Of Lines
考虑先把凸包找出来,如果凸包上的点数大于\(4\)显然不存在解,小于等于\(2\)必然存在解
否则枚举凸包上两个点连线,判断剩余点能否被一条线覆盖即可
view code
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define endl "\n"
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(s) scanf("%s",s)
#define pii pair<int,int>
#define pll pair<LL,LL>
#ifndef ONLINE_JUDGE
#define cout cerr
#endif
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x) cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
template <typename T> vector<T>& operator << (vector<T> &__container, T x){ __container.push_back(x); return __container; }
template <typename T> ostream& operator << (ostream &out, vector<T> &__container){ for(T _ : __container) out << _ << ' '; return out; }
const int MAXN = 2e5+7;
pii V(const pii &A, const pii &B){ return make_pair(B.first-A.first,B.second-A.second); }
LL cross(const pii &A, const pii &B){ return 1ll * A.first * B.second - 1ll * A.second * B.first; }
int sgn(LL x){ return x > 0 ? 1 : x < 0 ? -1 : 0; }
void solve(){
int n; sci(n);
vector<pii> point(n);
for(auto &p : point) sci(p.first), sci(p.second);
sort(all(point),[&](pii &A, pii &B){ return A.first==B.first?A.second<B.second:A.first<B.first; });
sort(point.begin()+1,point.end(),[&](pii &A, pii &B){
return atan2(A.second-point[0].second,A.first-point[0].first) < atan2(B.second-point[0].second,B.first-point[0].first);
});
static pii stk[MAXN];
static int top;
top = 0;
stk[++top] = point[0];
for(int i = 1; i < n; i++){
while(top>1 and sgn(cross(V(stk[top-1],stk[top]),V(stk[top-1],point[i])))<=0) top--;
stk[++top] = point[i];
}
if(top>=3 and sgn(cross(V(stk[1],stk[top]),V(stk[1],stk[top-1])))==0) top--;
if(top>4){
cout << "NO" << endl;
return;
}
if(top<=2){
cout << "YES" << endl;
return;
}
auto sameline = [&](const pii &A, const pii &B, const pii &C){
return sgn(cross(V(A,B),V(A,C))) == 0;
};
auto check = [&](const pii &A, const pii &B){
vector<bool> vis(n,false);
for(int i = 0; i < n; i++){
if(point[i]==A or point[i]==B) vis[i] = true;
if(sameline(A,B,point[i])) vis[i] = true;
}
vector<pii> vec;
for(int i = 0; i < n; i++) if(!vis[i]) vec << point[i];
if(vec.size()<=2) return true;
for(int i = 2; i < (int)vec.size(); i++) if(!sameline(vec[0],vec[1],vec[i])) return false;
return true;
};
for(int i = 1; i < top; i++) for(int j = i + 1; j <= top; j++) if(check(stk[i],stk[j])){
cout << "YES" << endl;
return;
}
cout << "NO" << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}
E.Tufurama
问题等价于:对于每个\(i\),我们需要知道\([i+1,a_i]\)之间有多少数大于等于\(i\)即可
由于\(a_i\)超过\(n\)没什么用,所以可以先把\(a_i\)和\(n\)取\(\min\),然后用主席树搞一下就好了
view code
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define endl "\n"
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(s) scanf("%s",s)
#define pii pair<int,int>
#define pll pair<LL,LL>
#ifndef ONLINE_JUDGE
#define cout cerr
#endif
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x) cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
template <typename T> vector<T>& operator << (vector<T> &__container, T x){ __container.push_back(x); return __container; }
template <typename T> ostream& operator << (ostream &out, vector<T> &__container){ for(T _ : __container) out << _ << ' '; return out; }
const int MAXN = 2e5+7;
struct SegmentTree{
int root[MAXN], sum[MAXN<<5], ls[MAXN<<5], rs[MAXN<<5], tot;
void modify(int &rt, int pre, int pos, int x, int l, int r){
rt = ++tot;
sum[rt] = sum[pre] + x; ls[rt] = ls[pre]; rs[rt] = rs[pre];
if(l+1==r) return;
int mid = (l + r) >> 1;
if(pos<mid) modify(ls[rt],ls[pre],pos,x,l,mid);
else modify(rs[rt],rs[pre],pos,x,mid,r);
}
int qsum(int Lrt, int Rrt, int L, int R, int l, int r){
if(L>=r or l>=R) return 0;
if(L<=l and r<=R) return sum[Rrt] - sum[Lrt];
int mid = (l + r) >> 1;
return qsum(ls[Lrt],ls[Rrt],L,R,l,mid) + qsum(rs[Lrt],rs[Rrt],L,R,mid,r);
}
}ST;
void solve(){
int n; sci(n);
vi A(n);
for(int &x : A) sci(x), cmin(x,n);
LL ret = 0;
for(int i = n; i; i--){
int x = A[i-1];
if(x>i) ret += ST.qsum(ST.root[x+1],ST.root[i+1],i,n+1,1,n+1);
ST.modify(ST.root[i],ST.root[i+1],x,1,1,n+1);
}
cout << ret << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}
F. k-substrings
直接二分是不行的,没有单调性
考虑枚举前后缀的中点\(i\),然后找以\(i\)和\(n-i+1\)为中点的最长相同串,可以发现这个长度是可以二分的,找到最长的相同串,这个用哈希就好了
view code
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define endl "\n"
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(s) scanf("%s",s)
#define pii pair<int,int>
#define pll pair<LL,LL>
#ifndef ONLINE_JUDGE
#define cout cerr
#endif
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x) cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
template <typename T> vector<T>& operator << (vector<T> &__container, T x){ __container.push_back(x); return __container; }
template <typename T> ostream& operator << (ostream &out, vector<T> &__container){ for(T _ : __container) out << _ << ' '; return out; }
const int MAXN = 1e6+7;
const int MOD1 = 998244353;
const int MOD2 = 1004525809;
const int BASE1 = 233;
const int BASE2 = 1033;
int n, pw1[MAXN], pw2[MAXN], ret[MAXN];
pii hax[MAXN];
char s[MAXN];
pii calc(int l, int r){
return make_pair((hax[r].first - 1ll * hax[l-1].first * pw1[r-l+1] % MOD1 + MOD1) % MOD1,
(hax[r].second - 1ll * hax[l-1].second * pw2[r-l+1] % MOD2 + MOD2) % MOD2);
}
void solve(){
sci(n); scs(s+1);
pw1[0] = pw2[0] = 1;
for(int i = 1; i < MAXN; i++) pw1[i] = 1ll * pw1[i-1] * BASE1 % MOD1, pw2[i] = 1ll * pw2[i-1] * BASE2 % MOD2;
for(int i = 1; i <= n; i++){
hax[i].first = (1ll * hax[i-1].first * BASE1 + s[i]) % MOD1;
hax[i].second = (1ll * hax[i-1].second * BASE2 + s[i]) % MOD2;
}
memset(ret,255,sizeof(ret));
for(int i = 1; i <= (n >> 1); i++){
int l = 1, r = i;
while(l<=r){
int mid = (l + r) >> 1;
if(calc(i-mid+1,i+mid-1)==calc(n-i+1-mid+1,n-i+1+mid-1)) l = mid + 1;
else r = mid - 1;
}
ret[i-r+1] = r * 2 - 1;
}
for(int i = 1; i <= (n + 1) / 2; i++) cout << (ret[i] = max(ret[i],ret[i-1] - 2)) << ' '; cout << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}
G. Partitions
每个值对答案的贡献次数是相同的,那么答案就是所有数的和\(sum\)乘上每个数的贡献数
第一种方法:
通过枚举指定数所在块的大小\(i\),选出\(i-1\)个数和指定数在同一块中,然后剩下的\(n-i\)个数分成\(k-1\)个集合,答案应该是\(sum\cdot\sum_{i=1}^{n-k+1}i\cdot \tbinom{n-1}{i-1}\cdot \operatorname{stirling}(n-i,k-1)\)
这样需要用任意模数\(NTT\)来算第二类斯特林数的列,比较麻烦
第二种方法:
对于指定的数,自身对自身的贡献为\(\operatorname{stirling}(n,k)\)而其他每个数只要和指定数在一个块内,就能有一次的贡献,考虑枚举把指定数和其他数捆绑在一起的方案数是\((n-1)\cdot\operatorname{stirling}(n-1,k)\),这时候答案就是\(sum\cdot (\operatorname{stirling}(n,k)+(n-1)\cdot \operatorname{stirling}(n-1,k))\)
view code
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define endl "\n"
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(s) scanf("%s",s)
#define pii pair<int,int>
#define pll pair<LL,LL>
#ifndef ONLINE_JUDGE
#define cout cerr
#endif
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x) cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
template <typename T> vector<T>& operator << (vector<T> &__container, T x){ __container.push_back(x); return __container; }
template <typename T> ostream& operator << (ostream &out, vector<T> &__container){ for(T _ : __container) out << _ << ' '; return out; }
const int MAXN = 2e5+7;
const int MOD = 1e9+7;
int fac[MAXN], inv[MAXN], rfac[MAXN];
int ksm(int a, int b){
int ret = 1;
while(b){
if(b&1) ret = 1ll * ret * a % MOD;
b >>= 1;
a = 1ll * a * a % MOD;
}
return ret;
}
int C(int n, int m){ return n < m ? 0 : 1ll * fac[n] * rfac[m] % MOD * rfac[n-m] % MOD; }
int stirling(int n, int m){
int ret = 0;
for(int i = 0; i < m; i++) ret = (ret + (i&1?-1ll:1ll) * C(m,i) % MOD * ksm(m-i,n) % MOD) % MOD;
return (1ll * ret * rfac[m] % MOD + MOD) % MOD;
}
void solve(){
int n, k;
sci(n); sci(k);
vi A(n); for(int &x : A) sci(x);
int tot = accumulate(all(A),0ll) % MOD;
if(n==k) cout << tot << endl;
else cout << 1ll * tot * (stirling(n,k) + 1ll * (n-1) * stirling(n-1,k) % MOD) % MOD << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
fac[0] = rfac[0] = inv[1] = 1;
for(int i = 1; i < MAXN; i++) fac[i] = 1ll * fac[i-1] * i % MOD;
for(int i = 2; i < MAXN; i++) inv[i] = 1ll * (MOD - MOD / i) * inv[MOD%i] % MOD;
for(int i = 1; i < MAXN; i++) rfac[i] = 1ll * rfac[i-1] * inv[i] % MOD;
solve();
return 0;
}
Educational Codeforces Round 41的更多相关文章
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- Educational Codeforces Round 41 B、C、D
http://codeforces.com/contest/961 B题 可以将长度为k的连续区间转化成1 求最大和 解析 简单尺取 #include <stdio.h> #include ...
- Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings
题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...
- Educational Codeforces Round 41 (Rated for Div. 2)(A~D)
由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...
- Educational Codeforces Round 41 (Rated for Div. 2)
这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Educational Codeforces Round 41 A B C D E
A. Tetris 题意 俄罗斯方块,问能得多少分. 思路 即求最小值 Code #include <bits/stdc++.h> #define F(i, a, b) for (int ...
- Educational Codeforces Round 41 E. Tufurama (961E)
[题解] 第一眼看题飞快地想到一种做法,然后假掉了. 这道题其实是主席树的模板题来着.但是也有别的水法. 我们可以发现每个位置的查询区间是[1,min(a[i],i-1)],所以我们可以把查询区间按照 ...
- D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))
#include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...
随机推荐
- 如何将项目推到github上面
1.先查看是否安装git. 2.如果没有安装git ,下载之后别忘了配置环境变量.(右击此电脑 --属性--高级系统设置--环境变量--系统变量中的path) 3.推代码 查看状态(可查可不查) gi ...
- Label_img&a
绝对路径 相对路径 从根目录开始写 从引用的文件所在目录开始写 也可以作为链接提示 target = _blank 新窗口打开 = _self 默认值 本窗口打开 = _new 新窗口打开 = _pa ...
- 对Java集合的概述
前言 大部分编程语言都提供了数组来保存对象,数组是非常重要的数据结构之一.但是数组在初始化时就已经定义了数组长度,不可变,使用起来颇为麻烦.因此,Java 在 JDK 1.2 版本中添加了集合框架,用 ...
- Java的nanoTime()方法
java有两个获取和时间相关的秒数方法,一个是广泛使用的 System.currentTimeMillis() 返回的是从一个长整型结果,表示毫秒. 另一个是 System.nanoTime() 返回 ...
- N叉树的最大深度-DFS
再看这道题之前,先来一道类似的简单题. 题目:求二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示 ...
- Redis 设计与实现 10:五大数据类型之有序集合
有序集合 sorted set (下面我们叫zset 吧) 有两种编码方式:压缩列表 ziplist 和跳表 skiplist. 编码一:ziplist zset 在 ziplist 中,成员(mem ...
- ruby+watir安装指南
安装ruby+watir一共需要下面几个步骤 1. 安装ruby: 2. 升级Rubygems:Rubygems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统. 它提供一个 ...
- 行业动态 | 利用Cassandra数据库揭开家族祖先的秘密
FamilySearch选择了基于Apache Cassandra的DataStax Enterprise (DSE)来加速用户增长,并通过更快的反应时间.高可用性以及零数据库宕机来提供强大的 ...
- Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details. To force a start use "systemctl reset-failed
安装docker时,自己添加了国内的hub.docker.com镜像 [root@ce-docker ~]# systemctl restart docker 出现以下报错:Job for docke ...
- SAPCAR使用说明
1.首先看一下SAPCAR的功能usage:create a new archive:SAPCAR -c[vir][f archive] [-P] [-C directory] [-A filen ...