답안 #683841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683841 2023-01-19T13:09:47 Z PoonYaPat Index (COCI21_index) C++14
110 / 110
1845 ms 255420 KB
#include <bits/stdc++.h>
using namespace std;

struct node {
    int val;
    node *L, *R;

    node(int val) : val(val),L(NULL),R(NULL) {}
    node(node *l, node *r) : val(0), L(l), R(r) {
        if (l) val+=l->val;
        if (r) val+=r->val;
    }
};

node* build(int l, int r) {
    if (l==r) return new node(0);
    else {
        int mid=(l+r)/2;
        return new node(build(l,mid),build(mid+1,r));
    }
}

node* update(node *v, int l, int r, int x, int val) {
    if (x>r || x<l) return v;
    if (l==r) return new node(v->val+val);
    int mid=(l+r)/2;
    return new node(update(v->L,l,mid,x,val),update(v->R,mid+1,r,x,val));
}

int query(node *v, int l, int r, int x, int y) {
    if (x>r || y<l) return 0;
    if (x<=l && r<=y) return v->val;
    int mid=(l+r)/2;
    return query(v->L,l,mid,x,y)+query(v->R,mid+1,r,x,y);
}

vector<node*> arr;
int n,q;
const int mx=200005;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>q;
    arr.push_back(build(1,mx));
    for (int i=1; i<=n; ++i) {
        int x; cin>>x;
        arr.push_back(update(update(arr.back(),1,mx,1,1),1,mx,x+1,-1));
    }

    while (q--) {
        int a,b; cin>>a>>b;
        int l=1,r=mx;
        while (l<r) {
            int mid=(l+r+1)/2;
            if (query(arr[b],1,mx,1,mid)-query(arr[a-1],1,mx,1,mid)>=mid) l=mid;
            else r=mid-1;
        }
        cout<<l<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14036 KB Output is correct
2 Correct 17 ms 14008 KB Output is correct
3 Correct 17 ms 14040 KB Output is correct
4 Correct 18 ms 14036 KB Output is correct
5 Correct 17 ms 14036 KB Output is correct
6 Correct 17 ms 13988 KB Output is correct
7 Correct 18 ms 14000 KB Output is correct
8 Correct 17 ms 13936 KB Output is correct
9 Correct 17 ms 14024 KB Output is correct
10 Correct 19 ms 14036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14036 KB Output is correct
2 Correct 17 ms 14008 KB Output is correct
3 Correct 17 ms 14040 KB Output is correct
4 Correct 18 ms 14036 KB Output is correct
5 Correct 17 ms 14036 KB Output is correct
6 Correct 17 ms 13988 KB Output is correct
7 Correct 18 ms 14000 KB Output is correct
8 Correct 17 ms 13936 KB Output is correct
9 Correct 17 ms 14024 KB Output is correct
10 Correct 19 ms 14036 KB Output is correct
11 Correct 301 ms 73256 KB Output is correct
12 Correct 262 ms 73340 KB Output is correct
13 Correct 278 ms 73408 KB Output is correct
14 Correct 267 ms 73284 KB Output is correct
15 Correct 275 ms 73240 KB Output is correct
16 Correct 273 ms 73408 KB Output is correct
17 Correct 263 ms 73276 KB Output is correct
18 Correct 280 ms 73412 KB Output is correct
19 Correct 275 ms 73260 KB Output is correct
20 Correct 276 ms 73280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14036 KB Output is correct
2 Correct 17 ms 14008 KB Output is correct
3 Correct 17 ms 14040 KB Output is correct
4 Correct 18 ms 14036 KB Output is correct
5 Correct 17 ms 14036 KB Output is correct
6 Correct 17 ms 13988 KB Output is correct
7 Correct 18 ms 14000 KB Output is correct
8 Correct 17 ms 13936 KB Output is correct
9 Correct 17 ms 14024 KB Output is correct
10 Correct 19 ms 14036 KB Output is correct
11 Correct 301 ms 73256 KB Output is correct
12 Correct 262 ms 73340 KB Output is correct
13 Correct 278 ms 73408 KB Output is correct
14 Correct 267 ms 73284 KB Output is correct
15 Correct 275 ms 73240 KB Output is correct
16 Correct 273 ms 73408 KB Output is correct
17 Correct 263 ms 73276 KB Output is correct
18 Correct 280 ms 73412 KB Output is correct
19 Correct 275 ms 73260 KB Output is correct
20 Correct 276 ms 73280 KB Output is correct
21 Correct 1734 ms 255296 KB Output is correct
22 Correct 1586 ms 255292 KB Output is correct
23 Correct 1663 ms 255300 KB Output is correct
24 Correct 1676 ms 255400 KB Output is correct
25 Correct 1845 ms 255420 KB Output is correct
26 Correct 1733 ms 255368 KB Output is correct
27 Correct 1627 ms 255328 KB Output is correct
28 Correct 1603 ms 255200 KB Output is correct
29 Correct 1718 ms 255328 KB Output is correct
30 Correct 1620 ms 255312 KB Output is correct