https://vjudge.net/contest/321565#problem/C 超时代码
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf 2147483647
#define N 10100
#define p(a) putchar(a)
#define For(i,a,b) for(register long long i=a;i<=b;++i)
//by war
//2019.8.22
using namespace std;
long long T,n,x,y,cnt,tot;
long long prime[N],mu[N],ans[];
bool vis[N]; struct dian{
long long l,r,t;
}a[N]; struct node{
long long n;
node *next;
}*e[N]; inline void in(long long &x){
long long y=;char c=getchar();x=;
while(c<''||c>''){if(c=='-')y=-;c=getchar();}
while(c<=''&&c>=''){ x=(x<<)+(x<<)+c-'';c=getchar();}
x*=y;
}
inline void o(long long x){
if(x<){p('-');x=-x;}
if(x>)o(x/);
p(x%+'');
} inline void push(long long x,long long y){
node *p;
p=new node();
p->n=y;
if(e[x]==)
e[x]=p;
else{
p->next=e[x]->next;
e[x]->next=p;
}
} void Euler(){
mu[]=;
For(i,,){
if(!vis[i]) prime[++cnt]=i,mu[i]=-;
for(register long long j=;j<=cnt&&i*prime[j]<=;j++){
vis[i*prime[j]]=;
if(i%prime[j]==){
mu[i*prime[j]]=;
break;
}
mu[i*prime[j]]=-mu[i];
}
}
} long long dfs(long long x,long long fa,long long w){
long long res=;
for(node *i=e[x];i;i=i->next)
if(i->n!=fa)
res+=dfs(i->n,x,w*a[i->n].t);
return res+w;
} inline long long F(register long long d){
long long res=,kk=;
For(i,,n){
a[i].t=a[i].r/d-a[i].l/d;
if(a[i].l%d==)
a[i].t++;
}
For(i,,n){
res+=dfs(i,i,a[i].t);
res-=a[i].t;
kk+=a[i].t;
}
return res/+kk;
} inline void clear(){
For(i,,)
e[i]=;
memset(ans,,sizeof(ans));
} signed main(){
in(T);
Euler();
while(T--){
clear();
in(n);
For(i,,n-){
in(x);in(y);
push(x,y);
push(y,x);
}
For(i,,n) in(a[i].l);
For(i,,n) in(a[i].r);
For(i,,)
for(register long long d=i;d<=;d+=i)
ans[i]+=mu[d/i]*F(d);
printf("Case %lld:\n",++tot);
For(i,,){
o(i);p(':');p(' ');
o(ans[i]);p('\n');
}
}
return ;
}
https://vjudge.net/contest/321565#problem/C 超时代码的更多相关文章
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
- https://vjudge.net/problem/2198220/origin
https://vjudge.net/problem/2198220/origin枚举等差数列第一个和第二个,然后二分确定数列后面是否存在,复杂度比较玄学,卡过了. #include<iostr ...
- https://vjudge.net/problem/2198221/origin
https://vjudge.net/problem/2198221/origin逆向思维,原题是人出来,我们处理成人进去,算出来每个人的曼哈顿距离,然后从大到小排序,距离长的先入.走的距离+这个人从 ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- .NET, NETCORE 怎么写 "超时"代码,解析"超时"代码原理!
干货:本人不会长篇大论.能贴上去的,就是干货,能用一两句话讲明白的,不会大讲概念,不会浪费大家宝贵的时间. 前言:我们发现,超时是个非常重要的概念,如果在通讯架构中,没有超时的设计,那么这个通讯架构就 ...
- http://vjudge.net/contest/view.action?cid=51142#problem/C 精度转换的一道题。。。
C - Get-Together at Den's Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & ...
- 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem A
Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
随机推荐
- MySQL慢查询日志分割
mysql> set global slow_query_log=0; Query OK, 0 rows affected (0.00 sec) mysql> set global s ...
- XML中的值得注意的"坑"
XML严禁 & < ,建议 < > & ' "进行转义 XML中预定义了5个实体引用: < > & ' " 其中,'<' ...
- utmp, wtmp - 登 录 记 录(login records)
SYNOPSIS[总览] #include DESCRIPTION[描述] utmp 文 件 用 于 记 录 当 前 系 统 用 户 是 哪 些 人. 但 是 实 际 的 人 数 可 能 比 这 个 ...
- struts2验证器
1. Struts2 的验证(note6,struts2-8) 1). 验证分为两种: > 声明式验证* >> 对哪个 Action 或 Model 的那个字段进行验证 >&g ...
- lsm和lkm模块
使用LSM Hook框架进行内核安全审计.元数据捕获,安全人员只需要按照既定的调用规范编写LKM模块,并加载进Linux内核,而不需要对system call lookup表进行任何修改 https: ...
- leetcode-两个数组交集(包含重复元素)
Python解法代码: class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: ...
- 图片转换为base64
明天中秋了,先祝大家中秋快乐!哈哈,最近见有人在群里问怎么把图片转换成base64格式,之前刚好写过就把代码贴出来. 主要用到canvas中的toDataURL方法 <!DOCTYPE html ...
- delphi编程实现为Windows窗口标题栏添加新按钮
下面我们就讨论一下在delphi中如何给窗口的标题栏上添加新的按钮. 一.实现起来要定义以下过程: 1. 定义DrawCaptButton过程,这个过程的功能是在指定的位置画出按钮. 在过程中要使用w ...
- Oozie安装
Oozie的安装与部署 1.解压Oozie $ tar -zxf /opt/softwares/oozie-4.0.0-cdh5.3.6.tar.gz -C /opt/modules/cdh/ 2.H ...
- VC图片裁剪源代码
#include <atlimage.h> int main() { CString filepathname = "D:\\1.png", filepathname1 ...