답안 #494341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494341 2021-12-15T08:22:28 Z ktkerem Index (COCI21_index) C++17
0 / 110
37 ms 392 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<llll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7; 
const ll ous=1e6 + 5;
const ll dx[4] = {1 , -1 , 0 , 0} , dy[4] = {0,0,-1,1};
struct node{
    ll mn=0 , mx=0 , cc=0; 
};
ll ar[ous];
node valt[ous];
struct segt{
    void build(ll a , ll l , ll r){
        if(l == r){
            valt[a].mn = ar[l];
            valt[a].mx = ar[l];
            valt[a].cc = 1;
            return;
        }
        ll mid = (l+r)/2;
        build(a*2 , l , mid);
        build(a*2+1 , mid+1 , r);
        valt[a].mn = min(valt[a*2].mn , valt[a*2+1].mn);
        valt[a].mx = max(valt[a*2].mx , valt[a*2+1].mx);
        valt[a].cc = valt[a*2].cc + valt[a*2+1].cc;
    }
    ll finds(ll a , ll l , ll r , ll nl , ll nr , ll val){
        if((nl > r || nr < l) || (valt[a].mx < val)){
            return 0;
        }
        if((r >= nr && l <= nl) && (valt[a].mn >= val)){
            return valt[a].cc;
        }
        ll mid = (nl + nr) / 2;
        ll lef = finds(a*2 , l , r , nl , mid , val);
        ll rig = finds(a*2+1 , l , r , mid+1 , nr , val);
        return lef+rig;
    }
};
void solve(){
    ll n , q;cin >> n >> q;
    fora(i,n){
        cin >> ar[i];
    }
    segt st;
    st.build(1 , 0 , n-1);
    while(q--){
        ll l , r;cin >> l >> r;
        l--;
        r--;
        ll yr = r-l+1 , yl = 1 , o = r-l+1;
        while(yr > yl){
            ll mid = (yr + yl)/2;
            ll y = st.finds(1 , l , r , 0 , n-1 , mid);
            //cout << mid << " " << y << "\n";
            if(y >= yr){
                yl = mid+1;
            }
            else{
                yr = mid;
            }
        }
        if(st.finds(1 , l , r , 0 , n-1 , yl) < yl){
            yl--;
        }
        cout << yl << "\n";
    }
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0; 
}

Compilation message

index.cpp: In function 'void solve()':
index.cpp:63:34: warning: unused variable 'o' [-Wunused-variable]
   63 |         ll yr = r-l+1 , yl = 1 , o = r-l+1;
      |                                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 392 KB Output isn't correct
2 Halted 0 ms 0 KB -