답안 #1094125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094125 2024-09-28T14:02:17 Z 0pt1mus23 Index (COCI21_index) C++14
110 / 110
1085 ms 14892 KB
#include <bits/stdc++.h>
using namespace std;
#define needforspeed ios::sync_with_stdio(0);cin.tie(0);
#define int long long int
#define pb push_back
#define ins insert
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<
const int mod = 1e9 +7,sze = 2e5 +23,inf = INT_MAX, L = 31; 
int block; 

int fener(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
    int x = a.first.first / block,y = b.first.first / block;
    if(x!=y){
        return a.first.first < b.first.first;
    }
    return a.first.second < b.first.second;
}
int tot =0;
int T[sze+23];
void upd(int node,int v){
    node++;
    while(node<=sze){
        T[node]+=v;
        node +=(node & -node);
    }
}
int qry2(int node){
    int sum=0;
    node++;
    while(node>0){
        sum+=T[node];
        node -= (node & -node);
    }
    return sum;
}

int qry(int node){
    return qry2(sze) - qry2(node -1);
}

void ekle(int v){
    tot+=v;
    upd(v,1);
    // cout<<"ekle: "<<v<<endl;

}
void sil(int v){
    tot-=v;
    upd(v,-1);
    // cout<<"sil: "<<v<<endl;
}
void opt1z(){
    int n,q;
    cin>>n>>q;
    block = ceil(sqrt(n));
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector<int> ans(q);

    vector<pair<pair<int,int>,int>> qq;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;l--;r--;
        qq.pb({{l,r},i});
    }
    sort(all(qq),fener);
    int cl = 0;
    int cr = -1;

    for(int i=0;i<q;i++){
        int l=qq[i].first.first;
        int r=qq[i].first.second;
        int idx = qq[i].second;

        while(cl>l){
            cl--;
            ekle(arr[cl]);
        }
        while(cr<r){
            cr++;
            ekle(arr[cr]);
        }
        while(cl<l){
            sil(arr[cl]);
            cl++;
        }
        while(cr>r){
            sil(arr[cr]);
            cr--;
        }
        int lx=1;
        int rx = r-l+1;
        int a=1;
        while(lx<=rx){
            int mid = (lx+rx)/2;
            // cout<<mid<<endl;
            if(qry(mid) >=mid){
                a=mid;
                lx = mid+1;
            }
            else{
                rx = mid-1;
            }
        }
        ans[idx]=a;
    }


    for(int i=0;i<q;i++) cout<<ans[i]<<endl;
}
 
signed main() {
    needforspeed;
 
    int tt = 1;
    // cin>>tt;
    while(tt--){
        opt1z();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 138 ms 4040 KB Output is correct
12 Correct 136 ms 4044 KB Output is correct
13 Correct 140 ms 4032 KB Output is correct
14 Correct 140 ms 4036 KB Output is correct
15 Correct 138 ms 4032 KB Output is correct
16 Correct 142 ms 3868 KB Output is correct
17 Correct 142 ms 4040 KB Output is correct
18 Correct 142 ms 4040 KB Output is correct
19 Correct 140 ms 4040 KB Output is correct
20 Correct 138 ms 4040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 138 ms 4040 KB Output is correct
12 Correct 136 ms 4044 KB Output is correct
13 Correct 140 ms 4032 KB Output is correct
14 Correct 140 ms 4036 KB Output is correct
15 Correct 138 ms 4032 KB Output is correct
16 Correct 142 ms 3868 KB Output is correct
17 Correct 142 ms 4040 KB Output is correct
18 Correct 142 ms 4040 KB Output is correct
19 Correct 140 ms 4040 KB Output is correct
20 Correct 138 ms 4040 KB Output is correct
21 Correct 1085 ms 14704 KB Output is correct
22 Correct 1080 ms 14776 KB Output is correct
23 Correct 1050 ms 14708 KB Output is correct
24 Correct 1038 ms 14776 KB Output is correct
25 Correct 1050 ms 14692 KB Output is correct
26 Correct 1045 ms 14772 KB Output is correct
27 Correct 1065 ms 14780 KB Output is correct
28 Correct 1048 ms 14892 KB Output is correct
29 Correct 1046 ms 14704 KB Output is correct
30 Correct 1065 ms 14832 KB Output is correct