codeforces 1181D

strange. Why is this question before I did not make up for three months. . .
Segment tree were teammates finished ah
https://blog.csdn.net/hzk_cpp/article/details/92797305
health of this

First, we have a [i] sort,
and in fact kept in the leveled period interval,
that is, before the number of all i and i + 1 becomes as large process.
We can easily determine what bulldozed where the number corresponds to what should be asked.
After the buck would not have pushed the level.

Now we need to find a small section k. That is the answer.
Obviously we can half a subscript and then stop and query prefix.
This thing with a single log segment tree well cast.
Then we use the same idea can be doubled in Fenwick tree.

its not right? ? ? Why does this problem have not seen for three months before I ah? ? ? ? This dichotomy is not a sucker tree line a few days ago (week) cf has just had a it? ? ?

Kinky odd learned skills
specific performance

#define 你老婆的名字 inline

Then you can add all your wife's name in front of each function.
Disgusting death house

#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';
    }
}

Guess you like

Origin www.cnblogs.com/MXang/p/11514344.html