codeforces 1181D

strangeness. Why didn't I answer this question three months ago? . .
The line segment tree has been written by teammates.
https://blog.csdn.net/hzk_cpp/article/details/92797305
Kang's this

First, we sort a[i],
and then in fact, we are constantly flattening a section,
that is, the process of turning all the first i numbers into the same size as i+1.
We can arbitrarily judge which queries should correspond to which numbers are flattened.
After it's fully leveled, you don't need to push it any more.

Now we need to find the kth smallest. That is the answer.
Obviously we can bisect a subscript and then keep querying the prefix sum.
This thing works well with a line segment tree and a single log.
Then we use the same idea to multiply on the tree array.

its not right? ? ? Why didn't I answer this question three months ago? ? ? ? Isn't this kind of stupid line segment tree bisection just a few days ago (week)? ? ?

Learned strange kinky skills,
which are manifested as

#define 你老婆的名字 inline

Then you can prefix each function with your wife's name.
Dead house is disgusting

#include <bits/stdc++.h>
#include <bits/extc++.h>
#define pii pair<ll,int>
#define sakuratxdy inline
using namespace std;
typedef long long ll;
const int N = 1e6+5;
ll bit[N];
int n,m,t;int a[N];
sakuratxdy int lowbit(int x){return x & -x;}
sakuratxdy void upd(int pos, int x){
    while (pos<N)bit[pos]+=x,pos+=lowbit(pos);
}
sakuratxdy int que(int pos){
    int res = 0;
    for(int i=19;i>=0;i--){
        if(res+(1<<i)<=m&&pos>bit[res+(1<<i)])
            pos-=bit[res+(1<<i)],res+=1<<i;
    }
    return res+1;
}
struct Node{
    ll val,id;
}node[N];
pii q[N];int ans[N];
bool cmp(Node a,Node b){
    return a.val<b.val||(a.val==b.val&&a.id<b.id);
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m>>t;
    for(int i=1;i<=n;i++)cin>>a[i],node[a[i]].val++;
    for(int i=1;i<=m;i++)node[i].id=i;
    sort(node+1,node+1+m,cmp);
    for(int i=1;i<=t;i++){
        cin>>q[i].first,q[i].second=i,q[i].first-=n;
    }
    sort(q+1,q+1+t);
    ll now = 0;int j=1;
    for(int i=1;i<m;i++){
        upd(node[i].id,1);
        while (j<=t&&q[j].first<=now+(node[i+1].val-node[i].val)*i){
            int t=(q[j].first-now)%i;
            ans[q[j++].second]=que(t==0?i:t);
        }
        now+=(node[i+1].val-node[i].val)*i;
    }
    upd(node[m].id,1);
    while (j<=t){//
        int t = (q[j].first-now)%m;
        ans[q[j++].second]=que(t==0?m:t);
    }
    for(int i=1;i<=t;i++){
        cout<<ans[i]<<'\n';
    }
}

Reprinted in: https://www.cnblogs.com/MXang/p/11514344.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326560165&siteId=291194637