题目链接

最后一题是Splay...还没有学会。。蒟蒻!!!

A

 /*************************************************************************
> File Name: A.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 13时33分32秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ int n, A[]; int main(void) {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = ; i < n; i++) cin >> A[i];
sort(A, A + n);
long long res = ;
for (int i = n - ; i >= ; i -= ) res += A[i];
cout << res << endl;
}
return ;
}

B

处理出每个素数在所有数中出现的次数最多的个数。

 /*************************************************************************
> File Name: B.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 13时36分46秒
> Propose:
************************************************************************/
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ typedef pair<int, int> pii;
const int MAX_N = ;
const int MAX_M = ;
bool vis[MAX_M];
int prime[MAX_N], A[MAX_N], cnt; void init() {
cnt = ;
memset(vis, false, sizeof(vis));
for (int i = ; i < MAX_M; i++) {
if (!vis[i]) {
prime[++cnt] = i;
for (int j = *i; j < MAX_M; j += i) vis[j] = true;
}
}
} #define rep(i, n) for (int i = (1); i <= (n); i++) vector<pii> factor(MAX_M);
vector<pii>::iterator it; void work(int x, int y) {
if (factor[x].second == ) {
factor[x].second = y; }
else {
factor[x].second = max(y, factor[x].second);
}
} int main(void) {
init();
ios::sync_with_stdio(false);
int t, n;
cin >> t;
while (t--) {
rep (i, MAX_M) factor[i-].second = ;
cin >> n;
rep (i, n) cin >> A[i];
rep (i, n) {
int x = A[i];
if (x == ) continue;
rep (j, cnt) {
if (prime[j]*prime[j] > A[i]) break;
if (x % prime[j] == ) {
int tmp = ;
while (x % prime[j] == ) tmp++, x /= prime[j];
work(prime[j], tmp);
}
}
  if (x > ) work(x, );
}
int res = ;
for (it = factor.begin(); it != factor.end(); ++it) {
res += it->second;
}
cout << res << endl;
} return ;
}

C

线段树。

对于第一种修改,就是区间减1

对于第二种修改,就是单点更新

最后,查询每个点2,3,5因子的个数。

 /*************************************************************************
> File Name: C.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月28日 星期日 14时06分24秒
> Propose:
************************************************************************/
#include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_N = ;
int factor[][MAX_N], A[MAX_N], id[MAX_N];
#define rep(i, n) for (int i = (1); i <= (n); i++)
#define lson(x) ((x<<1))
#define rson(x) ((x<<1) | 1) struct node {
int l, r, Min[];
}Tr[MAX_N<<]; void build(int rt, int l, int r) {
Tr[rt].l = l, Tr[rt].r = r;
rep(i, ) Tr[rt].Min[i-] = ;
if (l == r) {
rep (i, ) Tr[rt].Min[i-] = factor[i-][l];
id[l] = rt;
return ;
}
int mid = (l + r) / ;
build(lson(rt), l, mid);
build(rson(rt), mid + , r);
} void pushdown(int rt, int p) {
if (Tr[rt].Min[p] != ) {
Tr[lson(rt)].Min[p] += Tr[rt].Min[p];
Tr[rson(rt)].Min[p] += Tr[rt].Min[p];
Tr[rt].Min[p] = ;
}
} void update1(int rt, int l, int r, int p) {
if (Tr[rt].l >= l && Tr[rt].r <= r) {
Tr[rt].Min[p]--;
return ;
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) update1(lson(rt), l, r, p);
if (r > mid) update1(rson(rt), l, r, p);
} void update2(int rt, int l, int p, int d) {
if (Tr[rt].l == Tr[rt].r && Tr[rt].l == l) {
Tr[rt].Min[p] = d;
return ;
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) update2(lson(rt), l, p, d);
else update2(rson(rt), l, p, d);
} int query(int rt, int l, int p) {
if (Tr[rt].l == Tr[rt].r && Tr[rt].l == l) {
return max(Tr[rt].Min[p], );
}
pushdown(rt, p);
int mid = Tr[lson(rt)].r;
if (l <= mid) query(lson(rt), l, p);
else query(rson(rt), l, p);
} void read(int &res) {
res = ;
char c = ' ';
while (c < '' || c > '') c = getchar();
while (c >= '' && c <= '') res = res*+c-'', c = getchar();
} int POW(int a, int b) {
int res = ;
while (b) {
if (b & ) res *= a;
a *= a;
b >>= ;
}
return res;
} int main(void) {
int N, M, a[] = {, , , };
read(N);
rep (i, N) {
read(A[i]);
int x = A[i];
factor[][i] = factor[][i] = factor[][i] = ;
rep (j, ) {
int tmp = , p = a[j];
while (x % p == ) tmp++, x /= p;
factor[j-][i] = tmp;
}
A[i] = x;
}
build(, , N);
read(M);
int t, l, r, p, d, tmp;
while (M--) {
read(t);
if (t == ) {
read(l), read(r), read(p);
update1(, l, r, (p+)/-);
} else {
read(l), read(d);
rep (i, ) {
tmp = , p = a[i];
while (d % p == ) tmp++, d /= p;
update2(, l, i-, tmp);
}
A[l] = d;
}
}
rep (i, N) {
rep (j, ) {
tmp = query(, i, j-);
A[i] *= POW(a[j], tmp);
  }
   printf("%d%c", A[i], i == N ? '\n' : ' ');
} return ;
}

D

LTIME16小结(CodeChef)的更多相关文章

  1. 从零开始编写自己的C#框架(26)——小结

    一直想写个总结,不过实在太忙了,所以一直拖啊拖啊,拖到现在,不过也好,有了这段时间的沉淀,发现自己又有了小小的进步.哈哈...... 原想框架开发的相关开发步骤.文档.代码.功能.部署等都简单的讲过了 ...

  2. Python自然语言处理工具小结

    Python自然语言处理工具小结 作者:白宁超 2016年11月21日21:45:26 目录 [Python NLP]干货!详述Python NLTK下如何使用stanford NLP工具包(1) [ ...

  3. java单向加密算法小结(2)--MD5哈希算法

    上一篇文章整理了Base64算法的相关知识,严格来说,Base64只能算是一种编码方式而非加密算法,这一篇要说的MD5,其实也不算是加密算法,而是一种哈希算法,即将目标文本转化为固定长度,不可逆的字符 ...

  4. iOS--->微信支付小结

    iOS--->微信支付小结 说起支付,除了支付宝支付之外,微信支付也是我们三方支付中最重要的方式之一,承接上面总结的支付宝,接下来把微信支付也总结了一下 ***那么首先还是由公司去创建并申请使用 ...

  5. iOS 之UITextFiled/UITextView小结

    一:编辑被键盘遮挡的问题 参考自:http://blog.csdn.net/windkisshao/article/details/21398521 1.自定方法 ,用于移动视图 -(void)mov ...

  6. K近邻法(KNN)原理小结

    K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用.比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出 ...

  7. scikit-learn随机森林调参小结

    在Bagging与随机森林算法原理小结中,我们对随机森林(Random Forest, 以下简称RF)的原理做了总结.本文就从实践的角度对RF做一个总结.重点讲述scikit-learn中RF的调参注 ...

  8. Bagging与随机森林算法原理小结

    在集成学习原理小结中,我们讲到了集成学习有两个流派,一个是boosting派系,它的特点是各个弱学习器之间有依赖关系.另一种是bagging流派,它的特点是各个弱学习器之间没有依赖关系,可以并行拟合. ...

  9. scikit-learn 梯度提升树(GBDT)调参小结

    在梯度提升树(GBDT)原理小结中,我们对GBDT的原理做了总结,本文我们就从scikit-learn里GBDT的类库使用方法作一个总结,主要会关注调参中的一些要点. 1. scikit-learn ...

随机推荐

  1. pycharm远程调试和debug

    目的:     通过pycharm远程连接服务器,实现在pycharm上开发,代码同步到服务器(或者可以从服务器download到pycharm),利用服务器开发环境在pycharm上debug.   ...

  2. Swimming Balls

    Swimming Balls https://vjudge.net/contest/318752#problem/J如果直接算,各种球的情况都不清楚,因为放一个球之后,水位的变化也会影响之前放入的球, ...

  3. index方法用于数据集的强制索引操作

    index方法为3.2.3版本新增,用于数据集的强制索引操作,例如: $Model->index('user')->select(); 对查询强制使用user索引,user必须是数据表实际 ...

  4. HAVING方法也是连贯操作之一

    HAVING方法也是连贯操作之一,用于配合group方法完成从分组的结果中筛选(通常是聚合条件)数据. having方法只有一个参数,并且只能使用字符串,例如: $this->field('us ...

  5. promise体验

    promise的执行流程 promise串行执行异步 job1.then(job2).then(job3).catch(handleError); // 0.5秒后返回input*input的计算结果 ...

  6. iOS之CAGradientLayer属性简介和使用

    1.CAGradientLayer简介 CAGradientLayer用于制作背景图层的颜色渐变,也就是颜色梯度!相关属性简介: #import <QuartzCore/CALayer.h> ...

  7. SpringBoot学习笔记(五):SpringBoot集成lombok工具、SpringBoot集成Shiro安全框架

    SpringBoot集成lombok工具 什么是lombok? 自动生成setget方法,构造函数,打印日志 官网:http://projectlombok.org/features/index. 平 ...

  8. spring boot 中 rabbit mq基础例子

    1.先安装ELANG,再按照RabbitMQ 2.打开RabbitMQ控制台:rabbit command prompt 1.设置elang的路径:set ERLANG_HOME=D:\work_pr ...

  9. Python学习day09 - Python进阶(3)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  10. Django之模板语言(一)

    1.Django的模板语言(简而言之,字符串替换) 1.目前为止已经学过的模板语言: 1.{{ name }}  ------>变量 2. for 循环: {% for i in book_li ...