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)的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

    (施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...

  2. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  3. 计蒜客 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  ...

  4. The Preliminary Contest for ICPC Asia Nanjing 2019

    传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...

  5. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

  6. 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 ...

  7. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  8. 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 ...

  9. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

随机推荐

  1. Install Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4 on RHEL/CentOS 6.4/5.9 & Fedora 19-12 [转]

    Step 1: Installing Remi Repository ## Install Remi Repository on Fedora , , , , ## rpm -Uvh http://d ...

  2. 数据分析系列篇:玩转excel

    数据分析系列篇:玩转excel 不知道现在怎么也变得这么鸡婆,连excel都要准备写一篇.没办法,还有很多不是做数据的小伙伴们不会excel啊,抱着不抛弃.不放弃的态度,就讲下excel如何玩转.其实 ...

  3. Kafka启动报错

    文章目录 问题 解决 问题 通过 ./kafka-server-start.sh ../config/server.properties 启动kafka 之前在server.properties中修改 ...

  4. bash arithmatic

    Arithmetic in bash is done with $ and double parentheses: echo "$(($num1+$num2))" Or $ and ...

  5. Kattis - barcode

    Kattis - barcode 题目原文: To prepare for ACM-ICPC 2017 in Saigon, the host univeristy – Ho Chi Minh cit ...

  6. JsonSchema 启蒙

    jsonSchema 的应用场景有很多,毕竟现在各个接口传输数据基本都是json,比如你做测试想对部分json字段进行校验或者统计你该如何写?解析json获取字段然后if else?不是说不可以但是也 ...

  7. C# 线程池的使用 终止线程池中的队列

    C#的线程池使用起来还是非常简单的,这里记录一下. 根据http://blog.csdn.net/chen_zw/article/details/7939834里的描述这里记录一下C#线程池的特点 一 ...

  8. Python第五节 元组

    Python第八节 元组补充 元组从形式上看,和列表唯一不同的在于,列表是中括号,元组是小括号 元组内的元素不可更改 一. 创建 创建直接在小括号内写元素,用逗号隔开就好 创建空元祖只写一个小括号 元 ...

  9. react 数据发生变化,页面改变的原理

    数据发生变化,页面改变的原理: 比较虚拟的dom 不怎么损耗性能,真实的dom比较会损耗性能 1.state 数据 2.jsx 模板 3.生成虚拟的dom 3.数据和模板结合,生成虚拟的dom 4.用 ...

  10. python 文件复制压缩

    import os import time #这里是需要文件所在的位置 source=['"C:\\My Documents"',"C:\\Code"] #转换 ...