답안 #649503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649503 2022-10-10T10:20:12 Z NintsiChkhaidze Index (COCI21_index) C++14
110 / 110
1002 ms 82012 KB
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define left (h<<1),l,((l+r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define pii pair <int,int>
using namespace std;
 
const int N = 200005,m = 200000;

struct node {
	int l,r,val;
	node (){
		l = r = val = 0;
	}
};

int root[N],Nodes,lf,rg,a[N];
node t[32 * N];

int upd(int id,int l,int r,int pos){
	t[++Nodes] = t[id];
	id = Nodes;

	if (l == r){
		t[id].val++;
	}else{
		int mid = (l+r)/2;
		if(pos > mid) t[id].r = upd(t[id].r, mid + 1,r, pos);
		else t[id].l = upd(t[id].l, l, mid, pos);
		t[id].val = t[t[id].l].val + t[t[id].r].val;
	}

	return id;
}

int get(int id1, int id2,int l,int r,int L,int R){
	if (r < L || R < l) return 0;
	if (L <= l && r <= R) return t[id2].val - t[id1].val;
	int mid = (l+r)/2;
	return get(t[id1].l, t[id2].l, l, mid, L, R) + get(t[id1].r, t[id2].r, mid + 1, r, L, R);
}

bool check(int x){
	int k = get(root[lf - 1], root[rg], 1, m, x, m);
	return (k >= x);
}
int main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	
	int n,q;
	cin>>n>>q;

	for (int i = 1; i <= n; i++){
		cin>>a[i];
		root[i] = upd(root[i - 1], 1, m, a[i]);
	}
	
	while (q--){
		cin>>lf>>rg;

		int l=1,r = m,res=0;
		while (l <= r){
			int mid = (l + r)>>1;
			if (check(mid)) res = mid,l = mid + 1;
			else r = mid - 1;
 		}
		cout<<res<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 75468 KB Output is correct
2 Correct 42 ms 75468 KB Output is correct
3 Correct 36 ms 75468 KB Output is correct
4 Correct 40 ms 75456 KB Output is correct
5 Correct 39 ms 75484 KB Output is correct
6 Correct 37 ms 75468 KB Output is correct
7 Correct 39 ms 75488 KB Output is correct
8 Correct 46 ms 75464 KB Output is correct
9 Correct 43 ms 75400 KB Output is correct
10 Correct 40 ms 75468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 75468 KB Output is correct
2 Correct 42 ms 75468 KB Output is correct
3 Correct 36 ms 75468 KB Output is correct
4 Correct 40 ms 75456 KB Output is correct
5 Correct 39 ms 75484 KB Output is correct
6 Correct 37 ms 75468 KB Output is correct
7 Correct 39 ms 75488 KB Output is correct
8 Correct 46 ms 75464 KB Output is correct
9 Correct 43 ms 75400 KB Output is correct
10 Correct 40 ms 75468 KB Output is correct
11 Correct 238 ms 77032 KB Output is correct
12 Correct 228 ms 76936 KB Output is correct
13 Correct 252 ms 77100 KB Output is correct
14 Correct 199 ms 76968 KB Output is correct
15 Correct 212 ms 76968 KB Output is correct
16 Correct 197 ms 76876 KB Output is correct
17 Correct 184 ms 76920 KB Output is correct
18 Correct 201 ms 76968 KB Output is correct
19 Correct 204 ms 77092 KB Output is correct
20 Correct 210 ms 76908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 75468 KB Output is correct
2 Correct 42 ms 75468 KB Output is correct
3 Correct 36 ms 75468 KB Output is correct
4 Correct 40 ms 75456 KB Output is correct
5 Correct 39 ms 75484 KB Output is correct
6 Correct 37 ms 75468 KB Output is correct
7 Correct 39 ms 75488 KB Output is correct
8 Correct 46 ms 75464 KB Output is correct
9 Correct 43 ms 75400 KB Output is correct
10 Correct 40 ms 75468 KB Output is correct
11 Correct 238 ms 77032 KB Output is correct
12 Correct 228 ms 76936 KB Output is correct
13 Correct 252 ms 77100 KB Output is correct
14 Correct 199 ms 76968 KB Output is correct
15 Correct 212 ms 76968 KB Output is correct
16 Correct 197 ms 76876 KB Output is correct
17 Correct 184 ms 76920 KB Output is correct
18 Correct 201 ms 76968 KB Output is correct
19 Correct 204 ms 77092 KB Output is correct
20 Correct 210 ms 76908 KB Output is correct
21 Correct 906 ms 81848 KB Output is correct
22 Correct 893 ms 81952 KB Output is correct
23 Correct 896 ms 81932 KB Output is correct
24 Correct 874 ms 81824 KB Output is correct
25 Correct 931 ms 82012 KB Output is correct
26 Correct 903 ms 81904 KB Output is correct
27 Correct 869 ms 81932 KB Output is correct
28 Correct 897 ms 81836 KB Output is correct
29 Correct 949 ms 81964 KB Output is correct
30 Correct 1002 ms 81840 KB Output is correct