Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
594 B
2
Indexable
Never
 
#include <bits/stdc++.h>
 
using namespace std;
 
long long int n, k, x, y;
 
int solve(int x, int y, int n){
	int a=1<<(n-1);
	if(x==1 && y==1){ 
	    return 1;
	}
	if(x>a && y>a){ 
	    return solve(x-a, y-a, n-1)+3*a*a;
	}
	if(x>a && y<=a){ 
	    return solve(x-a, y, n-1)+2*a*a;
	}
	if(x<=a && y>a){ 
	    return solve(x, y-a, n-1)+a*a;
	}
	else{
	    return solve(x, y, n-1);
	}
}
 
int main()
{
    ifstream fin("z.in");
    ofstream fout("z.out");
 
	fin>>n>>k;
 
	for(int i=0; i<k; i++){
		fin>>x>>y;
		fout<<solve(x, y, n)<<"\n";
	}
	return 0;
}