【2018ACM/ICPC网络赛】徐州赛区
呃。自闭了自闭了。我才不会说我写D写到昏天黑地呢。
I Characters with Hash
题目链接:https://nanti.jisuanke.com/t/31461
题意:给你一个字符串s,一个种子字母L。根据 |int(L) - s[i]|公式的到hash后的字符,如果是个位数就变成两位数,最后去掉前导0计算字符串长度。也就是0->00 7->07.最后统计如果前面有0就都去掉。如果在中间qwq就不用啦。
题解:暴力模拟//先开始卡题意。。初始长度就设成2n好了。如果判断前面有0就-=2,如果是个位数的话-=1,后面都是长度为2啦。其实也就是判断一下最前面的字符即可。
虽然这题水,但是我真的卡题意了。都不好意思说自己过了六级。, 有个坑。。长度为0的时候输出1。
代码:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std; string s; int main(){
int T;
scanf("%d", &T);
while(T --){
int n;
char seed;
cin>>n>>seed;
cin>>s;
int ans = * n;
//只需要判断第一个是不是为0还是个位数
for(int i = ; i < n ;i++){
int tmp = abs(seed-s[i]);
if(tmp == ){
ans -= ;
}
else if(tmp < ){
ans -= ;
break;
}
else{
break;
}
}
if(ans == )
ans = ;
cout<<ans<<endl;
}
return ;
}
H Ryuji doesn't want to study
题目链接:https://nanti.jisuanke.com/t/31460
题意:两个操作,1、l,r 查询a[l]*Len + a[l+1]*(Len-1) … + a[r]的和。
2、b c,把a[b]->c
题解:树状数组维护一下a[i] * (r-i+1)的和,以及维护一下a[i]。。(学长的代码。!!超棒)
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long ll a[], b[], c[]; ll lowbit(ll x){
return x&(-x);
} int n;
ll sum(ll x){
ll s = ;
while(x > ){
s += c[x];
x -= lowbit(x);
}
return s;
} void add(int x, ll val){
while(x <= n){
c[x] += val;
x += lowbit(x);
}
} ll sum1(ll x){
ll s = ;
while(x > ){
s += b[x];
x -= lowbit(x);
}
return s;
} void add1(int x,ll val){
while( x <= n){
b[x] += val;
x += lowbit(x);
}
} int main(){
int q;
scanf("%d%d", &n, &q);
for(int i = ;i <= n; i++){
scanf("%lld", &a[i]);
add(i, a[i] * (n - i + ));
add1(i, a[i]);
}
for(int i = ; i <= q; i++){
int l, r, op;
scanf("%d", &op);
if(op == ){
scanf("%d%d", &l, &r);
printf("%lld\n", sum(r) - sum(l-) - (sum1(r) - sum1(l-)) * (n - r));
} else {
scanf("%d%d", &l, &r);
add(l, (r - a[l]) * (n - l + ));
add1(l, r - a[l]);
a[l] = r;
}
}
return ;
}
G Trace
题目链接:https://nanti.jisuanke.com/t/31459
题意:有一波一波的海浪,每一波海浪都会覆盖上一波的部分痕迹。求海浪打完后所留下的痕迹长度。海浪是个矩形,左下角0,0,右上角题目输入的x,y。
题解:这个题很毒。TLE了好多发。队友后面直接崩溃了。QAQ。用两个set维护。倒着求,找到当前比输入的x,y第一个小的sx,sy。ans += abs(x-sx),ans+= abs(y-sy)。大概这个意思。赛后在群里看到代码了才恍然大悟。emmm..还有就是对set不太熟悉。哎。
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <set>
using namespace std;
#define ll long long
const int maxn = 1e5+;
int n,m;
int x[maxn],y[maxn];
set<int> xx;
set<int> yy;
set<int>::iterator it;
ll ans = ;
void addl(int sx,int sy){
it = xx.lower_bound(sx);
if(it == xx.begin())
ans += sx;
else {
it--;
ans += sx - *it;
}
it = yy.lower_bound(sy);
if(it == yy.begin())
ans += sy;
else{
it--;
ans += sy - *it;
}
}
int main(){
cin>>n;
for(int i=; i<n; i++)
cin>>x[i]>>y[i];
for(int i = n-; i >= ; i--){
addl(x[i],y[i]);
xx.insert(x[i]);
yy.insert(y[i]);
}
cout<<ans<<endl;
return ;
}
接着更新哎。
D Easy Math
题目链接:https://nanti.jisuanke.com/t/31456
题意:计算$ ∑^{m}_{i = 1}$ µ (i*n)
题解:呃。真的不是很想面对这题。当时推出来直接上杜教筛,就被打爆了。对不起队友。
正经题解:
设f(m,n) = $ ∑^{m}_{i = 1}$ µ (i*n)
f(m,n) = $∑^{m}_{i = 1}$ µ(i)*µ(n) * [gcd(i,n) == 1]
= $∑^{m}_{i = 1}$ µ(i)*µ(n) * $∑_{ d|(i,n)}$µ(d)
= $\mu(n)\sum\limits_{d|n} \mu(d) \sum\limits^{\lfloor m/d \rfloor}_{i = 1} \mu(i*d)$
= $\mu(n)\sum\limits_{d|n} \mu(d) f(\lfloor (m/d) \rfloor,d)$
几种终止情况
m = 0,f(m,n) = 0
m = 1,f(m,n) = µ(n)
n = 1,f(m,n) =$\sum\limits^{m}_{i = 1} \mu(i)$ ->杜教筛
代码:
#include <cstdio>
#include <map>
#include <iostream>
#include <map>
using namespace std;
#define ll long long
const int N = 5e6; ll n,m; int mu[N+],pri[N+],top;
bool mark[N+];
map<ll,ll>V; int cnt;
ll p[N];
ll val[N];
int bit[N]; /*杜教筛*/
void init(){
mu[]=;
for(int i = ; i <= N; i++){
if(!mark[i]){
pri[++top] = i;
mu[i] = -;
}
for(int j = ; j <= top && i * pri[j] <= N; j++){
mark[ i * pri[j] ] = true;
if(i % pri[j] == )
break;
mu[ i * pri[j] ] = -mu[i];
}
}
for(int i = ; i <= N; i++)
mu[i] += mu[i-];
}
ll calc(ll x){
if(x <= N)
return mu[x];
if(V[x])
return V[x];
ll ans = ;
for(ll i = ,r; i <= x; i = r+){
r = x/(x/i);
ans -= calc(x/i) * (r-i+);
} V[x] = ans;
return ans;
} ll phi(ll x){
return ( (bit[x] & ) ? - : );
} ll solve(ll m, ll n) {
if (bit[n] == )
return calc(m);
if (m == )
return ;
if (m == )
phi(n);
ll ans = ;
for (ll i = n; ; i = (i-) & n){
ans += phi(i) * solve( m/val[i] , i);
if (!i)
break;
}
return ans * phi(n);
} int main(){
init();
cin>>m>>n;
ll x = n;
cnt = ;
int flag = ;
for( ll i = ; i * i <= x ;i++){
if(x%i == ){
//判断有偶数个因子
int t = (x/i) % i;
if(t == ){
flag = ;
break;
}
//不是的话加入
p[cnt++] = i;
while(x % i == ){
x /= i;
}
}
}
if(flag){
cout<<<<endl;
return ;
}
if(x > )
p[cnt++] = x;
for(int i = ; i < (<<cnt); i++){
bit[i] = ;
val[i] = ;
for(int j = ; j < cnt; j++){
if(i & (<<j) ){
bit[i]++;
val[i] *= p[j];
}
}
}
cout<<solve(m,(<<cnt)-)<<endl;
return ;
}
【2018ACM/ICPC网络赛】徐州赛区的更多相关文章
- 【2018ACM/ICPC网络赛】沈阳赛区
这次网络赛没有打.生病了去医院了..尴尬.晚上回来才看了题补简单题. K Supreme Number 题目链接:https://nanti.jisuanke.com/t/31452 题意:输入一个 ...
- 【2018ACM/ICPC网络赛】焦作赛区
A Magic Mirror 题目链接:https://nanti.jisuanke.com/t/31710 题意:输入字符串,如果是“Jessy”就输出“Good Guy!",否则输出“D ...
- 【icpc网络赛大连赛区】Sparse Graph
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submissi ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- Trace 2018徐州icpc网络赛 思维+二分
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...
- Features Track 2018徐州icpc网络赛 思维
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- 2019 徐州icpc网络赛 E. XKC's basketball team
题库链接: https://nanti.jisuanke.com/t/41387 题目大意 给定n个数,与一个数m,求ai右边最后一个至少比ai大m的数与这个数之间有多少个数 思路 对于每一个数,利用 ...
- Supreme Number 2018沈阳icpc网络赛 找规律
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
随机推荐
- cgroup & oom-killer 简介
cgroup内存限制 memory.failcnt memory.limit_in_bytes memory.usage_in_bytes memory.max_usage_in_bytes memo ...
- ASP.NET Core学习——5
日志(Logging)ASP.NET Core内建支持日志,也允许开发人员轻松切换为他们想用的其他日志框架. 通过dependency-injection请求ILoggerFactory或ILogge ...
- Java-Class-FC:java.lang.StringBuilder
ylbtech-Java-Class-FC:java.lang.StringBuilder 1.返回顶部 2.返回顶部 1. @Override public String toString() ...
- c#委托(Delegates)--基本概念及使用 转发
在我这菜鸟理解上,委托就是可以用方法名调用另一方法的便捷方法,可以简化switch等语句的重复.最近做项目的时候恰好需要用到委托,便来复习及学习委托的使用.嗯...本人以前并没有用过,只是稍微知道而已 ...
- Flink 编程模型
抽象层次 levels_of_abstraction 最低级的抽象接口是状态化的数据流接口(stateful streaming).这个接口是通过 ProcessFunction 集成到 Data ...
- drf中间件流程图
- redis 分析rdb中key
1.问题: 单位一个redis集群内存报警,想找出所有的key的列表? 2.解决办法: 网上搜索是可以用redis-rdb-tools 这个工具进行分析 (1)centos6 默认安装python2. ...
- Mariadb 10.2.8版本GTID主从环境搭建以及切换
1.首先搭建主从 主环境:192.168.1.117 从环境:192.168.1.123 a.首先以二进制包的形式安装好MariaDB (忽略不计) b.配置环境的变量 通配 [mysqld] bin ...
- Ubuntu桌面突然卡住,图形界面无反应
1.可能等待几分钟,系统会自动反应过来.你可以选择等待几分钟. 2.绝大多数情况系统是不会反应过来的,这时候可以进入tty终端直接注销用户. (1)Ubuntu有6个tty终端,按住Ctrl+Alt+ ...
- Laravel Route Resource 方法
新增的 resource 方法将遵从 RESTful 架构为用户资源生成路由.该方法接收两个参数,第一个参数为资源名称,第二个参数为控制器名称. Route::resource('users', 'U ...