Submission #857517

# Submission time Handle Problem Language Result Execution time Memory
857517 2023-10-06T10:27:57 Z 8pete8 Index (COCI21_index) C++17
0 / 110
1 ms 604 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
//#include "combo.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mod=1e9+7,mxn=2*1e5,inf=-1e10,lg=25;
int n,m;
bitset<mxn+10>yes;
struct node{
    node *l,*r;
    int val;
    node():val(0),l(0),r(0){}
};
node* root[mxn+10];
void build(node*&a,int l,int r){
    a=new node();
    int mid=l+(r-l)/2;
    if(l==r)return;
    build(a->l,l,mid);
    build(a->r,mid+1,r);
}
void update(node *&ncur,node *lcur,int val,int pos,int l,int r){
    ncur=new node(*lcur);
    if(l==r){
        ncur->val++;
        return;
    }
    int mid=l+(r-l)/2;
    if(pos<=mid) update(ncur->l,lcur->l,val,pos,l,mid);
    else update(ncur->r,lcur->r,val,pos,mid+1,r);
    ncur->val=ncur->l->val+ncur->r->val;
}
int qry(int l,int r,int ql,int qr,node *cur){
    if(ql>r||qr<l)return 0;
    if(ql<=l&&r<=qr)return cur->val;
    int mid=l+(r-l)/2;
    return qry(l,mid,ql,qr,cur->l)+qry(mid+1,r,ql,qr,cur->r);
}
vector<int>bs;
int32_t main(){
    fastio
    cin>>n>>m;
    build(root[0],1,n);
    vector<pii>v;
    v.pb({0,0});
    for(int i=1;i<=n;i++){
        int a;cin>>a;
        v.pb({a,i});
        if(!yes[a])bs.pb(a);
        yes[a]=true;
    }
    sort(rall(v));
    for(int i=0;i<n;i++)update(root[v[i].f],root[v[i-1].f],1,v[i].s,1,n);
    sort(all(bs));
    for(int i=0;i<m;i++){
        int ql,qr;cin>>ql>>qr;
        int ans=0;
        int l=0,r=bs.size()-1;
        while(l<=r){
            int mid=l+(r-l)/2;
            int cnt=qry(1,n,ql,qr,root[bs[mid]]);
            if(cnt>=bs[mid]){
                l=mid+1;
                ans=max(ans,bs[mid]);
            }
            else r=mid-1;
        }
        cout<<ans<<'\n';
    }

}

Compilation message

index.cpp: In constructor 'node::node()':
index.cpp:38:9: warning: 'node::val' will be initialized after [-Wreorder]
   38 |     int val;
      |         ^~~
index.cpp:37:11: warning:   'node* node::l' [-Wreorder]
   37 |     node *l,*r;
      |           ^
index.cpp:39:5: warning:   when initialized here [-Wreorder]
   39 |     node():val(0),l(0),r(0){}
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -