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. python之random随机函数

    random.random()用于生成 用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限.如果a > b,则生成随机数 1 n: a <= n <= b.如果 ...

  2. 利用IKVM在C#中调Java程序(总结+案例)

    IKVM.NET是一个针对Mono和微软.net框架的java实现,其设计目的是在.NET平台上运行java程序.本文将比较详细的介绍这个工具的原理.使用入门(如何java应用转换为.NET应用.), ...

  3. JSP 不能解析EL表达式的解决办法

    原文地址:http://www.jb51.net/article/30791.htm 原因是:在默认情况下,Servlet 2.4 / JSP 2.0支持 EL 表达式. 解决的办法有两种: 1.修改 ...

  4. linux日常---2、lamp.sh安装lamp环境中的linux操作

    linux日常---2.lamp.sh安装lamp环境中的linux操作 一.总结 一句话总结: 学不如用,学一百遍还不如真正多用几遍的来的效果好 1.linux下查看进程命令? ps 常用 ps - ...

  5. HDU6534 Chika and Friendly Pairs(莫队,树状数组)

    HDU6534 Chika and Friendly Pairs 莫队,树状数组的简单题 #include<bits/stdc++.h> using namespace std; cons ...

  6. lr_save_string和sprintf、lr_eval_string的使用

    一.lr_save_string函数 1.该函数主要是将程序中的常量或变量保存为参数: //将常量保存为参数 lr_save_string("777","page&quo ...

  7. 九、SpringBoot集成Thymeleaf模板引擎

    Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的.. ...

  8. RequestMapping 注解的解析、匹配、注册

    RequestMapping 注解的解析.匹配.注册 1)创建 RequestMappingHandlerMapping 实例时会触发 afterPropertiesSet 调用. 2)读取容器中所有 ...

  9. eclipse code recommenders cannot download its model repository index

    Cent OS 7 运行 eclipse oxygen 代码提示出现标题所示的错误,解决办法,将网络提供程序设置为手动即可解决. Window->Preference->General-& ...

  10. 【SQL系列】深入浅出数据仓库中SQL性能优化之Hive篇

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SQL系列]深入浅出数据仓库中SQL性能优化之 ...