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++. ...
随机推荐
- TI推出一款强大模拟设计与仿真工具TINA-TI 9.
德州仪器 (TI) 宣布推出一款基于 SPICE 的强大模拟设计与仿真工具 TINA-TI 9.1.该免费软件程序的最新版本与 7.0 版相比速度平均提高 5 倍,可帮助工程师在无任何节点或器件数量限 ...
- 数据库SQL调优的几种方式(转)
原文地址:https://blog.csdn.net/u010520146/article/details/81161762 在项目中,SQL的调优对项目的性能来讲至关重要,所有掌握常见的SQL调优方 ...
- ffmpeg -视频旋转和高清转码示例
手头有一个竖屏拍摄的视频(真诚建议不要这么做..),导入到电脑上以后势必要把它旋转90°,可是没想到就这样简单的一个功能,尝试了N个非编软件(openshot, pitivi,还有坑爹的lives)后 ...
- linux与Windows下的heap
Windows提供Heap相关的API,可以创建多个Heap. 但是Linux下只有一个意义上的Heap,就是Data Segment,由brk/sbrk系统调用来调整其大小. 参考:http://m ...
- upc组队赛12 Cardboard Container【枚举】
Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...
- upc组队赛6 Progressive Scramble【模拟】
Progressive Scramble 题目描述 You are a member of a naive spy agency. For secure communication,members o ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- Python List reverse() 与list[::-1]
reverse() https://www.runoob.com/python/att-list-reverse.html list[::-1] https://blog.csdn.net/usern ...
- [English]could, should, would, may 非單只是過去式
助動詞 could, should, would, may 的用法:(第三冊) 標題句:You should stay here. Would you like to order now? Could ...
- 算法竞赛模板 AC自动机
AC自动机基本操作 (1) 在AC自动机中,我们首先将每一个模式串插入到Trie树中去,建立一棵Trie树,然后构建fail指针. (2) fail指针,是穿插在Trie树中各个结点之间的指针,顾名思 ...