The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)
B. super_log
题意:研究一下就是求幂塔函数
%m的值。
思路:扩展欧拉降幂。

AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + ;
int a, b, m;
ll eular(ll n)
{
ll ans = n;
for(int i = ;i * i <= n;i++)
{
if(n % i == )
{
ans -= ans / i;
while(n % i == ) n /= i;
}
}
if(n != ) ans -= ans / n;
return ans;
}
int ksm(ll a, ll n, ll mod)
{
if(n == ) return ;
if(a <= ) return a;
if (n == )
return ;
if (a<=)
return a;
bool flag = false;
ll t = ;
for (int i = ; i < n; i++)
{
t = t*a;
if (t >= mod)
{
flag = true;
break;
}
}
ll ans = ;
while (n)
{
if (n & )
{
ans *= a;
ans %= mod;
}
a = a * a % mod;
n >>= ;
}
if (flag)
{
ans += mod;
}
return ans;
}
ll dfs(int a,int b,ll mod)
{
if (b == )
return ;
if (b == )
return a;
if (mod == )
return ;
ll h1 = ksm(a, dfs(a, b-, eular(mod)),mod);
return h1;
}
int main()
{
int t;
cin >>t;
while(t--)
{
cin >> a >> b >> m;
cout << dfs(a, b, m) % m << endl;
}
return ;
}
F. Greedy Sequence
题意:题意好绕的啊,自己看吧。
思路:用线段树查询区间最大值,因为对于每个数 i,只有比他小的数才有用,所以从小到大枚举,在线段树中(此时所有值都小于 i )。
AC代码:
#include<bits/stdc++.h>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define lr2 (l + r) / 2
const int maxn = 1e5+ ;
int n, k, a[maxn], pos[maxn];
int ans[maxn];
int sum[maxn* ] ;
void up(int rt){
sum[rt] = max(sum[ls], sum[rs]);
}
void build(int l ,int r, int rt)
{
sum[rt] = ;
if(l == r) return ;
int m = lr2;
build(lson);
build(rson);
up(rt);
}
int query(int a, int b, int l, int r, int rt)
{
if(a <= l && b >= r) return sum[rt];
int ans = ;
int m = lr2;
if(a <= m) ans = max(ans,query(a, b, lson));
if(b > m) ans = max(ans, query(a, b, rson));
return ans;
}
void update(int k, int v, int l, int r, int rt)
{
if(l == r){
sum[rt] = v;
return;
}
int m = lr2;
if(k <= m) update(k, v, lson);
else update(k, v, rson);
up(rt);
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = ;i <= n;i++){
cin >> a[i];
pos[a[i]] = i;
}
build(, n, );
for(int i = ;i <= n;i++)
{
int l = max(, pos[i] - k);
int r = min(n, pos[i] + k);
int x = query(l, r , , n, );
update(pos[i], i, , n, );
ans[i] = ans[x] + ;
}
for(int i = ;i <= n;i++){
cout << ans[i];
if(i == n)cout << endl;
else cout << " ";
}
}
return ;
}
H. Holy Grail
题意:给你一张n点m边的有向图,无重边,无负加权循环。请你加6对顶点,请你加6条权值最小的边使之没有负圈。
思路:每给一对顶点,跑一遍最短路,没有负环的条件是没有一条来的路和加的边加起来为负,所以每次加的边和答案为反向最短路。
AC代码:
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef pair<ll,int> P;
int n,m;
struct edge{
int to;
ll cost;
}es[maxn];
vector <edge> G[maxn];
ll d[maxn];
void dijkstra(int s)
{
priority_queue<P,vector<P>,greater<P> > que;
fill(d,d+m+,INF);
d[s] = ;
que.push(P(,s));
while(!que.empty())
{
P p= que.top();que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = ;i < G[v].size();i++)
{
edge e = G[v][i];;
if(d[e.to] > d[v] + e.cost)
{ d[e.to]= d[v] + e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie();std::cout.tie();
int t;
cin >> t;
while(t--)
{
cin >> n >> m;
for(int i = ;i <= n;i++)G[i].clear();
int count = ;
int a,b,c;
for(int i = ;i < m;i++)
{
cin >> a >> b >> c;
es[count].to = b;
es[count].cost = c;
G[a].push_back(es[count++]);
}
for(int i = ;i < ;i++){
cin >> a >> b;
dijkstra(b);
cout << -d[a] << endl;
es[count].to = b;
es[count].cost = -d[a];
G[a].push_back(es[count++]);
} } return ;
}
The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)的更多相关文章
- The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解
(施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...
- [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)
>传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...
- 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019
F Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each ...
- The Preliminary Contest for ICPC Asia Nanjing 2019
传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail
题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)
In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...
- 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019
题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...
- B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)
同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...
- H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...
随机推荐
- (57)C# frame4 调用frame2
http://msdn.microsoft.com/zh-cn/library/bbx34a2h.aspx https://www.cnblogs.com/weixing/archive/2012/0 ...
- idea下远程debug配置
一. 背景: 在测试工作中,为方便发现代码中的逻辑问题,尝试使用远程debug模式,在测试过程中走查代码,不仅可以辅助测试减少与开发的沟通成本,更便于了解业务提升测试深度. 二. 配置方式: 1. 调 ...
- shell编程:利用脚本实现nginx的守护自动重启
nginx_daemon.sh #!/bin/bash # this_pid=$$ while true do ps -ef | grep nginx | grep -v grep | grep -v ...
- CentOS 7 配置SFTP
目前越来越多的FTP客户端软件开始支持SSH协议上传和下载文件,这种协议方式就是SFTP. SFTP的优势主要有两点,一是不需要再配置个FTP服务端:二是SSH协议是安全传输,上传和下载是经过加密的. ...
- 热修复设计之CLASS_ISPREVERIFIED(二)
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从CLASS_ISPREVERIFIED实战来介绍热 ...
- spark复习总结03
1.DataFrame的创建方式 1.1 通过加载外部文件创建 //通过sqlContext读取json文件创建DataFrame DataFrame dataFrame=sqlContext.rea ...
- Inversion of Control 控制反转 有什么好处
作者:Mingqi链接:https://www.zhihu.com/question/23277575/answer/169698662来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- 《代码大全2》读书笔记 Week8
这一周博主阅读了<代码大全2>第11章至第13章,第三部分——"变量"就结束了,第四部分作者将转入语句的讨论. 第十一章作者详细阐述了变量名的有效命名规则,第十二和十三 ...
- js异步处理
一.什么是异步? 我们一般喜欢把异步和同步.并行拿出来比较,我以前的理解总是很模糊,总是生硬地记着“同步就是排队执行,异步就是一起执行”,现在一看,当初简直就是傻,所以我们第一步先把这三个概念搞清楚, ...
- 使用MySQL Workbench查询超时的错误
MySQL Workbench是MySQL提供的连接工具,一直在用它.但是今天运行了一个SQL缺报出如下的错误: errcode 2013 lost connection to mysql serve ...