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++. ...
随机推荐
- 建站手册-浏览器信息:Netscape 浏览器
ylbtech-建站手册-浏览器信息:Netscape 浏览器 1.返回顶部 1. http://www.w3school.com.cn/browsers/browsers_netscape.asp ...
- Linux中grep命令,用或的关系查询多个字符串,正则表达式基础说明
请尊重版权:原文:https://blog.csdn.net/lkforce/article/details/52862193 使用 grep 'word1|word2' 文件名 这样的命令是不对的 ...
- 数字三角形 (DP入门)
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 给出一个数字三角形.从三角形的顶部到底部有很多条不同的路径 ...
- __init__ 和__new__的区别
__init__和__new__的区别 __init__是当实例对象创建完成后被调用的,然后设置对象属性的一些初始值. __new__是在实例创建之前被调用的,因为它的任务就是创建实例然后返回该实例, ...
- UVA 12821 Double Shortest Paths
Double Shortest PathsAlice and Bob are walking in an ancient maze with a lot of caves and one-way pa ...
- offset 、 client 和 scroll - PC端网页特效
1.元素偏移量 offset 系列 1.1 offset 就是偏移量,使用 offset 系列相关属性可以 动态 得到该元素的位置(偏移).大小等. 注意: 1.获得元素距离带有定位父元素的位置 2 ...
- react 小技巧
1.当从redux里异步获取数据时,在render里渲染dom会出现数据还未获取到的情况,这时可以用 usableSchemas.data.vertexes && usableSche ...
- VS2013+Opencv3.3配置教程
转载自: https://blog.csdn.net/u014797226/article/details/78283873?locationNum=5&fps=1 参考博文1: 操作环境: ...
- 死磕Spring源码系列
一.Spring总体架构 1.架构图 2.SpringIOC:核心容器提供 Spring 框架的基本功能.核心容器的主要组件是 BeanFactory,它是工厂模式的实现.BeanFactory 使用 ...
- TCP协议中的三次握手和四次挥手(图解)(转)
转自:http://blog.csdn.net/whuslei/article/details/6667471 建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看 ...