Portal: https://vjudge.net/contest/363330#problem/A
Meaning of the questions, nxn matrix, each column is increasing, seeking what the entire matrix of small to large m-th number is
Error-prone Point: binary algorithm is to find a number x, which is smaller than a number of m, so that a reduction on the x and the like in the m-th number.
If you find a direct result res-half, smaller than the number of res have m-1 Ge, but then if m = 1, it will cause a dichotomous outcomes not the least that number.
Then half of each column when the idea is that, first find a position greater than or equal to k, is the current position of -1 to accumulate results
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #define maxn 50005 #define mod 1000000000 #define INF 0x3f3f3f3f using namespace std; typedef long long ll; ll n,m,ans; ll f(ll x,ll y) { return x * x + 100000 * x + y * y- 100000 * y + x * y; } ll calnum(ll k) { ll i,j; Le LL, RI, MID, SUM = 0 ; for (J = . 1 ; J <= n-; J ++) // for each column enum { the = 1 ; RI = n-+ . 1 ; the while (Le <RI) // Get the number k is less than { mid=(le+ri)>>1; if(f(mid,j)>=k) ri=mid; else le=mid+1; } sum + = to- 1 ; } return sum; } void solve() { ll le,mid,ri,t; ri=1LL<<50; Le = - RI; the while (Le <RI) // half answers { mid=(le+ri)>>1; t=calnum(mid); if(t>=m) ri=mid; else le=mid+1; } years = le 1 ; } int main () { int i,j,t; scanf("%d",&t); while(t--) { scanf("%lld%lld",&n,&m); solve(); printf("%lld\n",ans); } return 0; }