D - Square Pair
题目大意
- 给一长为
的数组
,问有多少对
,两者相乘为非负整数完全平方数
解题思路
- 一个数除以其能整除的最大的完全平方数,看前面有多少个与其余数相同的数,两者乘积满足条件(已经是完全平方数的部分无用)
- 对于0,特判(与%=0区分开)
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
static long md=(long)998244353;
static long Linf=Long.MAX_VALUE/2;
static int inf=Integer.MAX_VALUE/2;
public static void main(String[] args) throws IOException{
AReader input=new AReader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
HashMap hs=new HashMap();
int y=(int)Math.sqrt(a[i]);
bf=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
bw=new BufferedWriter(new OutputStreamWriter(System.out));
public String nextLine() throws IOException{
public String next() throws IOException{
while(!st.hasMoreTokens()){
st=new StringTokenizer(bf.readLine());
public char nextChar() throws IOException{
public int nextInt() throws IOException{
return Integer.parseInt(next());
public long nextLong() throws IOException{
return Long.parseLong(next());
public double nextDouble() throws IOException{
return Double.parseDouble(next());
public float nextFloat() throws IOException{
return Float.parseFloat(next());
public byte nextByte() throws IOException{
return Byte.parseByte(next());
public short nextShort() throws IOException{
return Short.parseShort(next());
public BigInteger nextBigInteger() throws IOException{
return new BigInteger(next());
public void println() throws IOException {
public void println(int[] arr) throws IOException{
public void println(int l, int r, int[] arr) throws IOException{
for (int i = l; i <= r; i ++) {
public void println(int a) throws IOException{
bw.write(String.valueOf(a));
public void print(int a) throws IOException{
bw.write(String.valueOf(a));
public void println(String a) throws IOException{
public void print(String a) throws IOException{
public void println(long a) throws IOException{
bw.write(String.valueOf(a));
public void print(long a) throws IOException{
bw.write(String.valueOf(a));
public void println(double a) throws IOException{
bw.write(String.valueOf(a));
public void print(double a) throws IOException{
bw.write(String.valueOf(a));
public void print(char a) throws IOException{
bw.write(String.valueOf(a));
public void println(char a) throws IOException{
bw.write(String.valueOf(a));

E - Last Train
题目大意
解题思路
- 单一汇点,多源点,反向建图
- 若当前时间为
,则到下一个点的时间为
- 则下一点最晚出发的时间为其等差数列中最大的小于
的时刻 - 由于有最晚出发时间的限制,所以不会有走环的情况
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
static long md=(long)998244353;
static long Linf=Long.MAX_VALUE/2;
static int inf=Integer.MAX_VALUE/2;
public Edge(int u,int v,long L,long D,long K,long C) {
static void addEdge(int fr,int to,long l,long d,long k,long c) {
e[cnt]=new Edge(fr, to, l, d, k, c);
public Node(int X,long D) {
public static void main(String[] args) throws IOException{
AReader input=new AReader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
addEdge(v, u, l, d, k, c);
PriorityQueue q=new PriorityQueue((o1,o2)->{
if(o2.dis-o1.dis>0)return 1;
else if(o2.dis-o1.dis<0)return -1;
long[] dis=new long[n+1];
q.add(new Node(n, Linf));
if(x!=n&&dis[x]>=now.dis)continue;
for(int i=head[x];i>0;i=e[i].nxt) {
may=l+Math.min((may-l)/d, k-1)*d;
for(int i=1;i
out.println("Unreachable");
}else out.println(dis[i]);
bf=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
bw=new BufferedWriter(new OutputStreamWriter(System.out));
public String nextLine() throws IOException{
public String next() throws IOException{
while(!st.hasMoreTokens()){
st=new StringTokenizer(bf.readLine());
public char nextChar() throws IOException{
public int nextInt() throws IOException{
return Integer.parseInt(next());
public long nextLong() throws IOException{
return Long.parseLong(next());
public double nextDouble() throws IOException{
return Double.parseDouble(next());
public float nextFloat() throws IOException{
return Float.parseFloat(next());
public byte nextByte() throws IOException{
return Byte.parseByte(next());
public short nextShort() throws IOException{
return Short.parseShort(next());
public BigInteger nextBigInteger() throws IOException{
return new BigInteger(next());
public void println() throws IOException {
public void println(int[] arr) throws IOException{
public void println(int l, int r, int[] arr) throws IOException{
for (int i = l; i <= r; i ++) {
public void println(int a) throws IOException{
bw.write(String.valueOf(a));
public void print(int a) throws IOException{
bw.write(String.valueOf(a));
public void println(String a) throws IOException{
public void print(String a) throws IOException{
public void println(long a) throws IOException{
bw.write(String.valueOf(a));
public void print(long a) throws IOException{
bw.write(String.valueOf(a));
public void println(double a) throws IOException{
bw.write(String.valueOf(a));
public void print(double a) throws IOException{
bw.write(String.valueOf(a));
public void print(char a) throws IOException{
bw.write(String.valueOf(a));
public void println(char a) throws IOException{
bw.write(String.valueOf(a));