Submission #937153

# Submission time Handle Problem Language Result Execution time Memory
937153 2024-03-03T14:34:52 Z goduadzesaba Index (COCI21_index) C++17
110 / 110
705 ms 42528 KB
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,q,a[N],ans[N],l[N],x[N],y[N],r[N],m[N],tree[N]; 
vector <int> v[N],que[N];
void update(int idx,int val){
	for (int i=idx; i<N; i+=i&(-i)) {
		tree[i]+=val;
	}
}
int get(int idx) {
	int ans=0;
	for (int i=idx; i>0; i-=i&(-i)) {
		ans+=tree[i];
	}
	return ans;
}
int main() {
	cin>>n>>q;
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		v[a[i]].push_back(i);
	}
	for (int i=1; i<=q; i++){
		cin>>x[i]>>y[i];
		l[i]=1; r[i]=200000; m[i]=(l[i]+r[i])/2;
	}
	while(true){
		int check=0;
		for (int i=1; i<=q; i++){
			if (l[i]>r[i]) continue;
			//cout<<l[i]<<" "<<r[i]<<endl;
			check=1;
			que[m[i]].push_back(i);
		}
		if(!check) break;
		for (int h=2e5; h>0; h--){
			for (int j:v[h]) {
				update(j, 1);
			//	cout<<h<<" "<<j<<" -------- > "<<1<<endl;
			}
			for (int j:que[h]){
				if(get(y[j])-get(x[j]-1)>=h){ // get(x[j], y[j])
					ans[j]=m[j]; l[j]=m[j]+1; 
				}
				else r[j]=m[j]-1; 

				m[j] = (l[j]+r[j])/2;
			}
		}
		for (int i=1; i<=2e5; i++) {
			for (int j:v[i]) {
				update(j, -1);
			}
			que[i].clear();
		}
	}
	for (int i=1; i<=q; i++) cout<<ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15192 KB Output is correct
2 Correct 19 ms 15092 KB Output is correct
3 Correct 19 ms 14940 KB Output is correct
4 Correct 19 ms 15048 KB Output is correct
5 Correct 18 ms 15192 KB Output is correct
6 Correct 17 ms 14940 KB Output is correct
7 Correct 17 ms 14940 KB Output is correct
8 Correct 18 ms 14940 KB Output is correct
9 Correct 17 ms 14936 KB Output is correct
10 Correct 18 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15192 KB Output is correct
2 Correct 19 ms 15092 KB Output is correct
3 Correct 19 ms 14940 KB Output is correct
4 Correct 19 ms 15048 KB Output is correct
5 Correct 18 ms 15192 KB Output is correct
6 Correct 17 ms 14940 KB Output is correct
7 Correct 17 ms 14940 KB Output is correct
8 Correct 18 ms 14940 KB Output is correct
9 Correct 17 ms 14936 KB Output is correct
10 Correct 18 ms 14940 KB Output is correct
11 Correct 150 ms 21636 KB Output is correct
12 Correct 144 ms 21508 KB Output is correct
13 Correct 183 ms 21304 KB Output is correct
14 Correct 146 ms 21452 KB Output is correct
15 Correct 144 ms 21480 KB Output is correct
16 Correct 144 ms 21736 KB Output is correct
17 Correct 152 ms 21420 KB Output is correct
18 Correct 154 ms 21404 KB Output is correct
19 Correct 151 ms 21428 KB Output is correct
20 Correct 172 ms 21472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15192 KB Output is correct
2 Correct 19 ms 15092 KB Output is correct
3 Correct 19 ms 14940 KB Output is correct
4 Correct 19 ms 15048 KB Output is correct
5 Correct 18 ms 15192 KB Output is correct
6 Correct 17 ms 14940 KB Output is correct
7 Correct 17 ms 14940 KB Output is correct
8 Correct 18 ms 14940 KB Output is correct
9 Correct 17 ms 14936 KB Output is correct
10 Correct 18 ms 14940 KB Output is correct
11 Correct 150 ms 21636 KB Output is correct
12 Correct 144 ms 21508 KB Output is correct
13 Correct 183 ms 21304 KB Output is correct
14 Correct 146 ms 21452 KB Output is correct
15 Correct 144 ms 21480 KB Output is correct
16 Correct 144 ms 21736 KB Output is correct
17 Correct 152 ms 21420 KB Output is correct
18 Correct 154 ms 21404 KB Output is correct
19 Correct 151 ms 21428 KB Output is correct
20 Correct 172 ms 21472 KB Output is correct
21 Correct 629 ms 42412 KB Output is correct
22 Correct 666 ms 42288 KB Output is correct
23 Correct 668 ms 42440 KB Output is correct
24 Correct 673 ms 42180 KB Output is correct
25 Correct 668 ms 42476 KB Output is correct
26 Correct 682 ms 42276 KB Output is correct
27 Correct 652 ms 42084 KB Output is correct
28 Correct 671 ms 42528 KB Output is correct
29 Correct 665 ms 42308 KB Output is correct
30 Correct 705 ms 42056 KB Output is correct