Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define int long long
- #define fo(i,n) for(int i = 0; i < n; i++)
- #define foll(i,n) for(ll i = 0; i < n; i++)
- int inf = 1e9+7,t=1,n,l,r,k,m,ans,temp,cur,sum,l1,r1,l2,r2,cnt,maxm,sto,defsolve,last;
- string s;
- int a[300005],b[300005],canbesolvedby[300001];
- vector<int> v,u;
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> t;
- // cout << "u0 " << flush;
- while(t--){
- cin >> n >> m;
- fo(i,n){
- cin >> a[i];
- }
- fo(i,m){
- cin >> b[i];
- }
- b[m] = inf;
- /* if (n==1){
- ans = 0;
- for (int i = 1; i <= m; i++){
- cout << (m/i) << " ";
- }
- cout << "\n";
- continue;
- }*/
- sort(b,b+m+1);
- v.clear();
- fo(i,m+1){
- v.push_back(b[i]);
- }
- // b.push_back(inf);
- /*itr = a.begin();
- itr++;
- sort(itr, a.end());*/
- defsolve = upper_bound(v.begin(),v.end(),a[0])-v.begin();
- v.pop_back();
- sort(a,a+n);
- u.clear();
- fo(i,n){
- u.push_back(a[i]);
- }
- // u.push_back(inf);
- //cout << "\n";
- fo (i,m){
- if (b[i] > a[n-1]){
- canbesolvedby[i] = 0;
- continue;
- }
- canbesolvedby[i] = n-(lower_bound(u.begin(),u.end(),b[i])-u.begin());
- // cout << b[i] << " " << canbesolvedby[i] << "\n" << flush;
- }
- for (int i = 1; i <= m; i++){
- ans = (defsolve/i);
- l = m;
- // cout << ans << "a ";
- if (defsolve%i != 0 && m != defsolve){
- ans += (canbesolvedby[l-i+(defsolve%i)])+1;
- l = l-i+(defsolve%i);
- }
- cnt = ((defsolve+i-1)/i);
- // cout << ans << " " << cnt << "b ";
- //cout << cnt << " " << flush;
- while (cnt < (m/i)){
- ans += (canbesolvedby[l-i])+1;
- l = l-i;
- cnt++;
- // cout << ans << "c ";
- }
- cout << ans << " ";
- }
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment