Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class D {
- // @formatter:off
- static long mod=(int)(1e9)+7;
- static FastScanner in;
- static class FastScanner{
- private InputStream stream;
- private byte[] buf = new byte[1 << 16];
- private int curChar;
- private int numChars;
- // standard input
- public FastScanner() { this(System.in); }
- public FastScanner(InputStream i) {
- stream = i;
- }
- // file input
- public FastScanner(String i) throws IOException {
- stream = new FileInputStream(i);
- }
- // throws InputMismatchException() if previously detected end of file
- private int nextByte() {
- if (numChars == -1) {
- throw new InputMismatchException();
- }
- if (curChar >= numChars) {
- curChar = 0;
- try {
- numChars = stream.read(buf);
- } catch (IOException e) {
- throw new InputMismatchException();
- }
- if (numChars == -1) {
- return -1; // end of file
- }
- }
- return buf[curChar++];
- }
- // to read in entire lines, replace c <= ' '
- // with a function that checks whether c is a line break
- public String next() {
- int c;
- do {
- c = nextByte();
- } while (c <= ' ');
- StringBuilder res = new StringBuilder();
- do {
- res.appendCodePoint(c);
- c = nextByte();
- } while (c > ' ');
- return res.toString();
- }
- public int nextInt() { // nextLong() would be implemented similarly
- int c;
- do {
- c = nextByte();
- } while (c <= ' ');
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = nextByte();
- }
- int res = 0;
- do {
- if (c < '0' || c > '9') {
- throw new InputMismatchException();
- }
- res = 10 * res + c - '0';
- c = nextByte();
- } while (c > ' ');
- return res * sgn;
- }
- public long nextLong() {
- int c;
- do {
- c = nextByte();
- } while (c <= ' ');
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = nextByte();
- }
- long res = 0;
- do {
- if (c < '0' || c > '9') {
- throw new InputMismatchException();
- }
- res = 10 * res + c - '0';
- c = nextByte();
- } while (c > ' ');
- return res * sgn;
- }
- public double nextDouble() { return Double.parseDouble(next()); }
- }
- static void setIO() {try {in=new FastScanner("test.in");}catch(Exception e) {in=new FastScanner(System.in);}}// @formatter:on
- public static void main(String[] args) {
- setIO();
- int n=in.nextInt(),p=in.nextInt();
- int[]a=new int[n];
- for(int i=0;i<n;i++)a[i]=in.nextInt();
- Arrays.sort(a);
- Map<Integer, Integer>cmp=new HashMap<>();
- int c=0;
- for(int i=n-1;i>=0;i--) {
- if(cmp.containsKey(a[i])) continue;
- dfs(a[i],cmp,c++);
- }
- List<Integer>starting=new ArrayList<>();
- boolean[]v=new boolean[n];
- for(int i=0;i<n;i++) {
- int comp=cmp.get(a[i]);
- if(v[comp]) continue;
- starting.add(a[i]);
- v[comp]=true;
- }
- // System.out.println(cmp);
- // System.out.println(starting);
- Long[]dp=new Long[p]; // up to p
- solve(0,dp);
- long ret=0;
- for(int start:starting) {
- int log=log2(start);
- if(log>=p) continue;
- ret+=dp[log];
- ret%=mod;
- }
- System.out.println(ret);
- }
- static void dfs(int curr, Map<Integer, Integer>cmp,int c) {
- if(curr<=0) return;
- cmp.put(curr, c);
- if(curr%2==1) dfs(curr/2,cmp,c);
- else if(curr%4==0) dfs(curr/4,cmp,c);
- }
- static int log2(int a) {
- int ret=0;
- while(a>1) {
- a/=2;
- ret++;
- }
- return ret;
- }
- static long solve(int curr, Long[]dp) {
- if(curr>=dp.length) return 0;
- if(curr==dp.length-1) return dp[curr]=1l;
- if(curr==dp.length-2) return dp[curr]=2l;
- if(dp[curr]!=null) return dp[curr];
- dp[curr]=(1+solve(curr+1,dp)+solve(curr+2,dp))%mod;
- return dp[curr];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement