nowcoder提高组2题解
T1
化一下试子就ok
code
#include<cstdio>
#include<algorithm>
inline long long read() {
long long x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {if(c == '-')f = -1; c = getchar(); }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
long long n;
long long a[100007];
long long sum[100007];
long long sum2[100007];
int main() {
n = read();
for(long long i = 1;i <= n;++ i) a[i] = read(),sum[i] = sum[i - 1] + a[i],sum2[i] = sum2[i - 1] + a[i] * a[i];
for(long long i = 1;i <= n;++ i) {
long long s1 = sum2[i - 1] + sum2[n] - sum2[i];
long long s = sum[i - 1] + sum[n] - sum[i];
long long ans = (n - 1) * s1 - s * s ;
if(i != n) printf("%lld ",ans);
else printf("%lld",ans);
}
return 0;
}
T2
设\(g(n)\)为长为n的环的方案数
设\(f(n)\)为长为n的序列方案书
容易得到递推式
\(g(n) = f(n) - g(n - 1)\)
由于\(a_1>a_n\)的时候不好处理,我们直接把环转一下,让1位置为最小值
对于\(f(n)\)可以容斥求得
f_i = (-1)^{i} \sum_j\min(a[j+1...i]) \times f_j \times (-1)^{j-1}\]
考虑 i 转移到 i+1 时候:
\]
单调栈为维护一下就好了,单调栈维护
code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define pc putchar
#define gc getchar
inline int read() {
int x = 0,f = 1;
char c = gc();
while(c < '0' || c > '9') c = gc();
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc();
return x * f;
}
#define LL long long
const int mod = 1000000007;
void print(LL x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10)print(x / 10);
pc(x % 10 + '0');
}
#define INF 0x3f3f3f3f3f3f3f3fLL
const int maxn = 4000007;
LL a[maxn],b[maxn];
int n;
inline void mo(LL &x,LL y) {
x = ((x + y ) % mod + mod) % mod;
}
LL st[maxn][3];
int main() {
n = read();
a[1] = read();
if(n == 1) {
print(a[1]);
}
int mn = 1;
for(int i = 2;i <= n;++ i) {
a[i] = read();
if(a[i] < a[mn]) mn = i;
}
for(int i = 1;i <= n;++ i) b[i] = a[(mn + i - 2) % n + 1];
int tp = 1;
memset(a,0,sizeof a);
LL ans = 0;
a[0] = n & 1 ? -1 : 1;
st[1][0] = INF,
st[1][1] = a[0];
for(int i = 1;i <= n;++ i) {
LL sum = 0;
for(;tp && b[i] < st[tp][0]; -- tp) mo(sum,st[tp][1]);
mo(a[i],-st[tp][2] - sum * b[i]);
st[++ tp][0] = b[i];
st[tp][1] = sum;
st[tp][2] = (sum * b[i] + st[tp - 1][2]) % mod;
st[++ tp][0] = INF;
st[tp][1] = a[i];
mo(ans,a[i]);
}
mo(ans,n & 1? - b[1]:b[1]);
print(ans);
}
T3
- 假设 \(\{1,2,\dots, n\}\in S\)
那么一定存在一个 \(i\) ,使得 \(\forall U\) 使得 \(i\in U\), 必有 \(U\in S\) .
(如果不存在,那么 \(\forall i, \exists i\in V_i, V_i\in T\) ,那么 \(\{1,2,\dots, n\}=\bigcup_i V_i \in T\),矛盾) - 假设 \(\{1,2,\dots, n\}\in T\)
那么一定存在一个 \(i\) ,使得 \(\forall U\) 使得 \(i\in U\), 必有 \(U\in T\) .
(如果不存在,那么 \(\forall i, \exists i\in V_i, V_i\in S\) ,那么 \(\{1,2,\dots, n\}=\bigcup_i V_i \in S\),矛盾)
\(2^0 , 2^1, \dots, 2^{n-1}\) ,
假设 \(K=2^{a_0}+2^{a_1}+\dots +2^{a_s}\)
咕咕咕
nowcoder提高组2题解的更多相关文章
- Nowcoder 提高组练习赛-R7
Nowcoder 提高组练习赛-R7 https://www.nowcoder.com/acm/contest/179#question 中间空了两场,因为实在是太难了... 第五场的第二题好像还比较 ...
- 【题解】NOIP2017 提高组 简要题解
[题解]NOIP2017 提高组 简要题解 小凯的疑惑(数论) 不讲 时间复杂度 大力模拟 奶酪 并查集模板题 宝藏 最优解一定存在一种构造方法是按照深度一步步生成所有的联通性. 枚举一个根,随后设\ ...
- 【题解】NOIP2016 提高组 简要题解
[题解]NOIP2016 提高组 简要题解 玩具迷题(送分) 用异或实现 //@winlere #include<iostream> #include<cstdio> #inc ...
- Nowcoder 提高组练习赛-R1
https://www.nowcoder.com/acm/contest/172#question 单人报名300元,五人合报免费,于是就和学弟同学学长们组了一个三世同堂的队伍,高一的学长wzhqwq ...
- nowcoder 提高组模拟赛 最长路 解题报告
最长路 链接: https://www.nowcoder.com/acm/contest/178/A 来源:牛客网 题目描述 有一张 \(n\) 个点 \(m\) 条边的有向图,每条边上都带有一个字符 ...
- NOIP2017提高组day2T1题解(奶酪)
题目链接:奶酪 这道题还是很水的,在下拿了满分. 并没有用什么高级的算法,我讲一下基本思路. 我们把每个洞都视为一个节点. 我们读入相关数据后,就先进行预处理,通过每个节点的信息和题目的规定,建立一张 ...
- Nowcoder 提高组练习赛-R3
https://www.nowcoder.com/acm/contest/174#question 今天的题好难呀,只有94个人有分.然后我就爆零光荣 考到一半发现我们班要上物理课,还要去做物理实验( ...
- Nowcoder 提高组练习赛-R2
https://www.nowcoder.com/acm/contest/173#question T1:https://www.nowcoder.com/acm/contest/173/A 题意概述 ...
- nowcoder 提高组模拟赛 选择题 解题报告
选择题 链接: https://www.nowcoder.com/acm/contest/178/B 来源:牛客网 题目描述 有一道选择题,有 \(a,b,c,d\) 四个选项. 现在有 \(n\) ...
随机推荐
- ubuntu14.04 VIM for python 一键配置
# 超强vim配置文件 [](https://travis-ci. ...
- 【ARTS】01_10_左耳听风-20190114~20190120
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Python Tools for Machine Learning
Python Tools for Machine Learning Python is one of the best programming languages out there, with an ...
- 驱动开发--【字符设备、块设备简介】【sky原创】
驱动开发 字符设备,块设备,网络设备 字符设备 以字节流的方式访问, 不能随机访问 有例外,显卡.EEPROM可以随机访问 EEPROM可以擦写1亿次,是一种字符设备,可以随机访问 读写是 ...
- MySQL在线更改binlog格式
今天变更jboss报错如下: SQLWarning ignored: SQL state ', message [Unsafe statement written to the binary log ...
- js里的回调函数
function a(callback) // 定义一个函数 ,需要传入的参数是callback 然后callback的类型为一个函数{console.log("callback还表示传 ...
- openstack常见问题解决方法总结
一.创建实例失败: 首先用下面命令查看服务是否正常 1. nova-manage service list 如果不正常,则使用下面命令重启,如果还不行,则查看日志, 1. service nova-a ...
- 常用的4个eclipse插件安装过程及使用方法
最近整合了4个常用eclipse插件安装过程,分别是PMD.checkstyle.findbugs.sourcemonitor插件.因为我这里没有外网,所以所有的插件不是最新版,建议有网的童鞋自行在外 ...
- 使用NGINX+Openresty和unixhot_waf开源防火墙实现WAF功能
使用NGINX+Openresty实现WAF功能 一.了解WAF1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: ...
- Androi:ViewPager
Android ViewPager控件的使用(基于ViewPager的横向相册)!!!: http://blog.csdn.net/Android_Tutor/article/details/7980 ...