头像

一切随缘




离线:15小时前


最近来访(29)
用户头像
蓝泽
用户头像
cc150
用户头像
bobo2010
用户头像
墨染樱飞
用户头像
陈信长
用户头像
Ymw123
用户头像
沐秋
用户头像
tongfs
用户头像
花殇
用户头像
JIeJaitt
用户头像
大雪莱
用户头像
我舅是太阳
用户头像
levelna
用户头像
chen_zhe_Aya
用户头像
lhang55
用户头像
从零开始的之旅
用户头像
Joseph1314
用户头像
edgdcgxgbx
用户头像
我要出去乱说
用户头像
独孤三段

活动打卡代码 AcWing 875. 快速幂

一切随缘
16小时前
import java.io.*;

public class Main {

    static int qmi(int a, int b, int p) {
        int res = 1 % p;

        while (b > 0) {
            if (b % 2 == 1) res = (int)((long)res * a % p);
            a = (int)((long)a * a % p);
            b /= 2;
        }
        return res;
    }


    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());

        while (n -- > 0) {
            String[] arr = in.readLine().split(" ");
            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            int p = Integer.parseInt(arr[2]);

            System.out.println(qmi(a, b, p));
        }
    }
}


活动打卡代码 AcWing 1236. 递增三元组

import java.util.*;
import java.io.*;

public class Main {
    static int N = 100010;
    static int n;
    static int[] a = new int[N];
    static int[] b = new int[N];
    static int[] c = new int[N];
    static int[] as = new int[N];
    static int[] cs = new int[N];
    static int[] s = new int[N];
    static int[] cnt = new int[N];

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static int Int(String s) {
        return Integer.parseInt(s);
    }

    public static void main(String[] args) throws Exception{
        n = Int(in.readLine());
        String[] x = in.readLine().split(" ");
        String[] y = in.readLine().split(" ");
        String[] z = in.readLine().split(" ");

        for (int i = 0; i < n; i ++ ) {
            a[i] = Int(x[i]) + 1;
            b[i] = Int(y[i]) + 1;
            c[i] = Int(z[i]) + 1;
        }

        for (int i = 0; i < n; i ++ ) cnt[a[i]] ++ ;
        for (int i = 1; i < N; i ++ ) s[i] = s[i - 1] + cnt[i];
        for (int i = 0; i < n; i ++ ) as[i] = s[b[i] - 1];

        Arrays.fill(cnt, 0);
        Arrays.fill(s, 0);

        for (int i = 0; i < n; i ++ ) cnt[c[i]] ++ ;
        for (int i = 1; i < N; i ++ ) s[i] = s[i - 1] + cnt[i];
        for (int i = 0; i < n; i ++ ) cs[i] = s[N - 1] - s[b[i]];

        long res = 0;
        for (int i = 0; i < n; i ++ ) res += (long)as[i] * cs[i];
            out.write(res + "");

        out.flush();
        in.close();
    }
}




import java.util.*;
import java.io.*;

public class Main {
    static int N = 100010;
    static int n;
    static int[] a = new int[N];
    static int[] b = new int[N];
    static int[] c = new int[N];
    static int[] as = new int[N];
    static int[] cs = new int[N];
    static int[] s = new int[N];
    static int[] cnt = new int[N];

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static int Int(String s) {
        return Integer.parseInt(s);
    }

    public static void main(String[] args) throws Exception{
        n = Int(in.readLine());
        String[] x = in.readLine().split(" ");
        String[] y = in.readLine().split(" ");
        String[] z = in.readLine().split(" ");

        for (int i = 0; i < n; i ++ ) {
            a[i] = Int(x[i]) + 1;
            b[i] = Int(y[i]) + 1;
            c[i] = Int(z[i]) + 1;
        }

        for (int i = 0; i < n; i ++ ) cnt[a[i]] ++ ;
        for (int i = 1; i < N; i ++ ) s[i] = s[i - 1] + cnt[i];
        for (int i = 0; i < n; i ++ ) as[i] = s[b[i] - 1];

        Arrays.fill(cnt, 0);
        Arrays.fill(s, 0);

        for (int i = 0; i < n; i ++ ) cnt[c[i]] ++ ;
        for (int i = 1; i < N; i ++ ) s[i] = s[i - 1] + cnt[i];
        for (int i = 0; i < n; i ++ ) cs[i] = s[N - 1] - s[b[i]];

        long res = 0;
        for (int i = 0; i < n; i ++ ) res += (long)as[i] * cs[i];
            out.write(res + "");

        out.flush();
        in.close();
    }
}




import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0, b = 1, c = 0;
        for (int i = 0; i < n; i++ ) {
            System.out.print(a + " ");
            c = a + b;
            a = b;
            b = c;
        }
    }
}



import java.util.*;
import java.io.*;

public class Main {
    static int N = 30;
    static int n, m;
    static int[] way = new int[N];
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception{
        String[] str = in.readLine().split(" ");
        n = Integer.parseInt(str[0]);
        m = Integer.parseInt(str[1]);
        dfs(1, 1);
        out.flush();
        in.close();
    }

    public static void dfs(int u, int start) throws Exception{
        if (u + n - start < m) return;

        if (u == m + 1) {
            for (int i = 1; i <= m; i ++ ) out.write(way[i] + " ");
            out.write("\n");

            return;
        } 

        for (int i = start; i <= n; i ++ ) {
            way[u] = i;
            dfs(u + 1, i + 1);
            way[u] = 0;
        }
    }
}



import java.io.*;

public class Main {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static int n;
    static int m;
    static int[] p = new int[100010];

    public static void main(String[] args) throws Exception{
        String[] strs = in.readLine().split(" ");
        int n = Integer.parseInt(strs[0]);
        int m = Integer.parseInt(strs[1]);
        for (int i = 1; i <= n; i ++ ) {
            p[i] = i;
        }

        while (m -- > 0) {
            String[] str = in.readLine().split(" ");
            int a = Integer.parseInt(str[1]);
            int b = Integer.parseInt(str[2]);
            if (str[0].equals("M")) {
                if (find(a) == find(b)) continue;
                else {
                    p[find(a)] = find(b);
                }
            } else {
                if (find(a) == find(b)) out.write("Yes\n");
                else out.write("No\n");
            }
        }

        out.flush();
        in.close();
    }

    public static int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }
}



import java.io.*;

public class Main{
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static int n;
    static int[] path = new int[8];
    static boolean[] st = new boolean[8];
    public static void main(String[] args) throws Exception{
        n = Integer.parseInt(in.readLine());
        dfs(0);
        out.flush();
        in.close();
    }
    public static void dfs(int u) throws Exception{
        if (u == n) {
            for (int i = 0; i < n; i ++ ) {
                out.write(path[i] + " ");
            }
            out.write("\n");
            return;
        }
        for (int i = 1; i <= n; i ++ ) {
            if (!st[i]) {
                path[u] = i;
                st[i] = true;
                dfs(u + 1);
                st[i] = false;
            }
        }
    }
}  



import java.io.*;

public class Main {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws Exception{
        String[] strs = in.readLine().split(" ");
        int n = Integer.parseInt(strs[0]);
        int m = Integer.parseInt(strs[1]);
        int q = Integer.parseInt(strs[2]);
        int[][] a = new int[n + 1][m + 1];
        int[][] s = new int[n + 1][m + 1];

        for (int i = 1; i <= n; i ++ ) {
            String[] str1 = in.readLine().split(" ");
            for (int j = 1; j <= m; j ++ ) {
                a[i][j] = Integer.parseInt(str1[j - 1]);
            }
        }

        for (int i = 1; i <= n; i ++ ) {
            for (int j = 1; j <= m; j ++ ) {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
            }
        }

        while (q -- > 0) {
            String[] str2 = in.readLine().split(" ");
            int x1 = Integer.parseInt(str2[0]);
            int y1 = Integer.parseInt(str2[1]);
            int x2 = Integer.parseInt(str2[2]);
            int y2 = Integer.parseInt(str2[3]);
            out.write(s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] + "\n");
        }
        out.flush();
        in.close();
    }
}



import java.io.*;

public class Main {
    static int N = 100010;
    static int[] a = new int[N];
    static int[] b = new int[N];
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception{
        String[] strs = in.readLine().split(" ");
        int n = Integer.parseInt(strs[0]);
        int m = Integer.parseInt(strs[1]);
        String[] q = in.readLine().split(" ");
        for (int i = 1; i <= n; i ++ ) {
            a[i] = Integer.parseInt(q[i - 1]);
        }
        for (int i = 1; i <= n; i ++ ) {
            b[i] = a[i] - a[i - 1];
        }

        while (m -- > 0) {
            String[] str = in.readLine().split(" ");
            int l = Integer.parseInt(str[0]);
            int r = Integer.parseInt(str[1]);
            int c = Integer.parseInt(str[2]);
            b[l] += c;
            b[r + 1] -= c;
        }
        for (int i = 1;i <= n; i ++ ) {
            a[i] = a[i - 1] + b[i];
            out.write(a[i] + " ");
        }
        out.flush();
        in.close();
    }
}



import java.io.*;

public class Main {
    static int N = 100010;
    static int[] a = new int[N];
    static int[] s = new int[N];
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws Exception{
        String[] strs = in.readLine().split(" ");
        int n = Integer.parseInt(strs[0]);
        int m = Integer.parseInt(strs[1]);

        String[] str = in.readLine().split(" ");
        for (int i = 1; i <= n; i ++ ) {
            a[i] = Integer.parseInt(str[i - 1]);
        }
        for (int i = 1; i <= n; i ++ ) {
            s[i] = s[i - 1] + a[i];
        }
        while (m -- > 0) {
            String[] q = in.readLine().split(" ");
            int l = Integer.parseInt(q[0]);
            int r = Integer.parseInt(q[1]);
            out.write(s[r] - s[l - 1] + "\n");
        }
        out.flush();
        in.close();
    }
}