A

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
int num[];
int pre[];
int n;
int number;
bool check()
{
for (int i = ; i <= n; i++)
{
pre[i] = pre[i - ] + pre[i];
if (pre[i] < )
{
return false;
}
}
return true;
}
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> number;
for (int i = ; i <= number; i++)
{
cin >> num[i];
}
for (int i = ; i <= ; i++)
{
for (int j = ; j <= n; j++)
{
pre[j] = ;
}
for (int j = ; j <= number; j++)
{
if (i == )
{
pre[num[j]] += ;
pre[num[j] + ] += -;
}
else
{
pre[max(, num[j] - i + )] += ;
pre[num[j] + i] += -;
}
}
if (check())
{
cout << i << endl;
break;
}
}
}
return ;
}

B

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
int le[];
int re[];
int wait[];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
{
scanf("%d %d", &le[i], &re[i]);
}
int cur = le[];
for (int i = ; i < n; i++)
{
cur = max(cur, le[i]);
if (re[i] >= cur)
{
wait[i] = cur;
cur++;
}
else
{
wait[i] = ;
}
}
for (int i = ; i < n; i++)
{
cout << wait[i];
if (i != n - )
{
cout << " ";
}
}
cout << endl;
}
return ;
}

C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
int num[];
int pre[];
char f[];
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%d", num + i);
}
scanf("%s", f + );
for (int i = ; i < n; i++)
{
if (f[i] == '')
{
pre[i] = pre[i - ] + ;
}
else
{
pre[i] = ;
}
}
for (int i = ; i < n; i++)
{
if (pre[i] > pre[i + ])
{
sort(num + i - pre[i] + , num + i + );
}
}
for (int i = ; i < n; i++)
{
if (num[i] != i)
{
cout << "NO" << endl;
return ;
}
}
cout << "YES" << endl;
return ;
}

E

把所有点放在一个set里,每次取set中一个顶点,删去,遍历set,删去与此顶点邻接的顶点

因为遍历的过程中有两种结局1.删去某个结点 遍历成功 2.两点之间不存在边 遍历失败

所以遍历的总复杂度为O(n+m) 再加上set的复杂度就是 O((n+m)log)

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
set<int> need;
map<int, bool> mp[];
vector<int> ans;
int main()
{
int n, m;
int from, to;
cin >> n;
for (int i = ; i <= n; i++)
{
need.insert(i);
}
cin >> m;
for (int i = ; i <= m; i++)
{
scanf("%d %d", &from, &to);
mp[from][to] = mp[to][from] = ;
}
while (!need.empty())
{
int todo = *need.begin();
need.erase(todo);
queue<int> que;
ans.push_back();
que.push(todo);
while (!que.empty())
{
queue<int> shan;
int cnt = que.front();
que.pop();
ans.back()++;
for (auto i : need)
{
if (!mp[cnt][i])
{
que.push(i);
shan.push(i);
}
}
while (!shan.empty())
{
need.erase(shan.front());
shan.pop();
}
}
}
cout << ans.size() << endl;
sort(ans.begin(), ans.end());
for (auto i : ans)
{
cout << i << " ";
}
cout << endl;
return ;
}

F

如果知道到N的因数(N%i==0)数量级是N^(1/3)的这道题就很好做了 因为当N=1或者N=2时因数数目等于N 而1e6=2^20 每个数最多被修改7次

所以线段树维护一个最大值 一个sum值 当最大值不大于2时不用修改 大于二时递归下去暴力修改

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
ll n, q;
int l, r;
ll dp[];
struct node
{
ll maxn, sum;
} tree[];
void pushup(int x)
{
tree[x].sum = tree[x << ].sum + tree[x << | ].sum;
tree[x].maxn = max(tree[x << ].maxn, tree[x << | ].maxn);
}
void build(int x, ll value, int root = , int l = , int r = n)
{
if (l > x || r < x)
{
return ;
}
if (l == x && r == x)
{
tree[root].sum = tree[root].maxn = value;
return;
}
int mid = (l + r) >> ;
if (x <= mid)
{
build(x, value, root << , l, mid);
}
else
{
build(x, value, root << | , mid + , r);
}
pushup(root);
}
void update(int xl, int xr, int root = , int l = , int r = n)
{
if (l > r || l > xr || r < xl)
{
return;
}
if (xl <= l && xr >= r && tree[root].maxn <= )
{
return;
}
if (l == r)
{
tree[root].sum = tree[root].maxn = dp[tree[root].sum];
return ;
}
int mid = (l + r) >> ;
if (xl <= mid)
{
update(xl, xr, root << , l, mid);
}
if (xr > mid)
{
update(xl, xr, root << | , mid + , r);
}
pushup(root);
}
ll getsum(int xl, int xr, int root = , int l = , int r = n)
{
if (l > r || l > xr || r < xl)
{
return ;
}
if (xl <= l && xr >= r)
{
return tree[root].sum;
}
int mid = (l + r) >> ;
return getsum(xl, xr, root << , l, mid) + getsum(xl, xr, root << | , mid + , r);
}
int main()
{
cin >> n >> q;
ll cnt;
for (int i = ; i <= ; i++)
{
for (int j = i; j <= ; j += i)
{
dp[j]++;
}
}
for (int i = ; i <= n; i++)
{
scanf("%lld", &cnt);
build(i, cnt);
}
for (int i = ; i <= q; i++)
{
int now;
ll value;
int aim;
cin >> now;
if (now == )
{
scanf("%d %d", &l, &r);
update(l, r);
}
else
{
scanf("%d %d", &l, &r);
cout << getsum(l, r) << endl;
}
}
return ;
}

Codeforces 920 反图联通块 线段树质因数暴力的更多相关文章

  1. Codeforces 920 E Connected Components?

    Discription You are given an undirected graph consisting of n vertices and  edges. Instead of giving ...

  2. Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)

    题目链接:http://codeforces.com/contest/616/problem/C 题意就是 给你一个n行m列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个), ...

  3. Codeforces 731C. Socks 联通块

    C. Socks time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input o ...

  4. Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量

    D. Directed Roads   ZS the Coder and Chris the Baboon has explored Udayland for quite some time. The ...

  5. PAT A1013 Battle Over Cities (25 分)——图遍历,联通块个数

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  6. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树

    E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...

  7. 【UVA10765】Doves and bombs (BCC求割点后联通块数量)

    题目: 题意: 给了一个联通无向图,现在问去掉某个点,会让图变成几个联通块? 输出的按分出的从多到小,若相等,输出标号从小到大.输出M个. 分析: BCC求割点后联通块数量,Tarjan算法. 联通块 ...

  8. 链表加bfs求补图联通块

    https://oj.neu.edu.cn/problem/1387 给一个点数N <= 100000, 边 <= 1000000的无向图,求补图的联通块数,以及每个块包含的点数 由于点数 ...

  9. bzoj2200拓扑排序+最短路+联通块

    自己写的不知道哪里wa了,明明和网上的代码差不多.,. /* 给定一张图,有的边是无向边,有的是有向边,有向边不会出现在环中,且有可能是负权值 现在给定起点s,求出s到其余所有点的最短路长度 任何存在 ...

随机推荐

  1. Java的LinkedList底层源码分析

    首先我们先说一下,源码里可以看出此类不仅仅用双向链表实现了队列数据结构的功能,还提供了链表数据结构的功能.

  2. install_github无法安装 Rwebdriver包的解决方法

    1.通过install_githtb安装Rwebdriver包的错误如下: 提示不能打开URL,但是将URL地址输入浏览器地址栏,则可以下载包到本地 2.在网上搜索,发现可以通过本地文件来安装(ins ...

  3. Flutter工程目录

    1 目录结构 当使用flutter create myapp 创建纯flutter项目后,会自动生成初始化代码. 需要注意一下几个文件夹 2 资源 像图片.视频.文字等这些资源文件,在 Flutter ...

  4. ubuntu的无线网无法连上

    自己的笔记本可以连上wireless,但是实验室的台式机无法连上. 有无线显示,就是无法连上. 后来把连在机箱上的网线拔了以后可以连无线了.如果有网线连接,系统优先会选择有线的上网.

  5. Delphi XE2 之 FireMonkey 入门(39) - 控件基础: TScrollBox、TVertScrollBox、TFramedScrollBox、TFramedVertScrollBox

    Delphi XE2 之 FireMonkey 入门(39) - 控件基础: TScrollBox.TVertScrollBox.TFramedScrollBox.TFramedVertScrollB ...

  6. 阶段3 1.Mybatis_07.Mybatis的连接池及事务_4 mybatis中使用unpooled配置连接池的原理分析

    把之前的CRUD的代码src下的代码都复制过来 依赖项也都复制过来, 配置文件 整理一番 执行findAll方法的测试 查看日志的输出部分 修改程序池 再来执行findAll方法 Plooled从连接 ...

  7. CSS样式div

    页面中,有很多样式标签:div标签,对标签定位的地方有: 1.<head>标签里加<style>标签,在<style>标签中添加样式.如: <style> ...

  8. Python学习之==>Excel操作

    一.简介 使用Python读.写.修改excel分别需要用到xlrd.xlwt以及xlutils模块,这几个模块使用pip安装即可. 二.读excel import xlrd book = xlrd. ...

  9. centos7安装java JDK

    Java环境 1.下载jdk(用FileZilla或xshell工具连接服务器后上传到需要安装的目录) 在 /opt/deploy 下新建 java 文件夹: # mkdir / opt/deploy ...

  10. QA的工作职责是什么?

    目前不知道,后续一点一点查资料补充吧 QA不管做什么的类型的测试,最基础的功能测试,需要搭建测试环境:进阶部分的性能压力测试,对搭建环境的要求更高:接口功能测试,搭建测试环境,和功能测试的差不多: 测 ...