Submission #970240

# Submission time Handle Problem Language Result Execution time Memory
970240 2024-04-26T09:10:16 Z blacktulip Index (COCI21_index) C++17
110 / 110
1458 ms 237052 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long lo; 

#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<

const lo inf = 1000000000;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,a[li],k,flag,t;
int cev;
string s;

struct Node{
	Node* left;
	Node* right;
	int val;
	Node(){
		val=0;
		left=NULL;
		right=NULL;
	}
	Node(Node* k){
		val=k->val;
		left=k->left;
		right=k->right;
	}
};

inline void update(Node* node,int start,int end,int l,int r,int val){
	if(node==NULL || start>r || end<l)return ;
	if(start>=l && end<=r){node->val+=val;return ;}
	if(node->left==NULL)node->left=new Node();
	else node->left=new Node(node->left);
	if(node->right==NULL)node->right=new Node();
	else node->right=new Node(node->right);
	update(node->left,start,mid,l,r,val);
	update(node->right,mid+1,end,l,r,val);
	node->val=node->left->val+node->right->val;
	//~ cout<<node->val _ start _ end<<endl;
}

inline int query(Node* node,int start,int end,int l,int r){
	if(node==NULL || start>r || end<l)return 0;
	if(start>=l && end<=r)return node->val;
	return query(node->left,start,mid,l,r)+query(node->right,mid+1,end,l,r);
}

int32_t main(void){
	fio();
	cin>>n>>t;
	FOR cin>>a[i];
	Node* tmp=new Node();
	vector<Node*> v;
	v.pb(tmp);
	FOR{
		Node* root=new Node(v[i-1]);
		update(root,1,200000,a[i],a[i],1);
		v.pb(root);
	}
	while(t--){
		int l,r;
		cin>>l>>r;
		int bas=1;
		int son=200000;
		//~ cout<<query(v[r],1,200000,1,200000) _ l _ r<<endl;
		while(bas<=son){
			int at=query(v[r],1,200000,ort,200000)-query(v[l-1],1,200000,ort,200000);
			if(at>=ort)bas=ort+1;
			else son=ort-1;
		}
		cout<<son<<endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1624 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
3 Correct 3 ms 1648 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1504 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1628 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1624 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
3 Correct 3 ms 1648 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1504 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1628 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
11 Correct 213 ms 60980 KB Output is correct
12 Correct 199 ms 61132 KB Output is correct
13 Correct 232 ms 60940 KB Output is correct
14 Correct 204 ms 61092 KB Output is correct
15 Correct 218 ms 60968 KB Output is correct
16 Correct 223 ms 60984 KB Output is correct
17 Correct 216 ms 61128 KB Output is correct
18 Correct 243 ms 61032 KB Output is correct
19 Correct 206 ms 60944 KB Output is correct
20 Correct 279 ms 61128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1624 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
3 Correct 3 ms 1648 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1504 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1628 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
11 Correct 213 ms 60980 KB Output is correct
12 Correct 199 ms 61132 KB Output is correct
13 Correct 232 ms 60940 KB Output is correct
14 Correct 204 ms 61092 KB Output is correct
15 Correct 218 ms 60968 KB Output is correct
16 Correct 223 ms 60984 KB Output is correct
17 Correct 216 ms 61128 KB Output is correct
18 Correct 243 ms 61032 KB Output is correct
19 Correct 206 ms 60944 KB Output is correct
20 Correct 279 ms 61128 KB Output is correct
21 Correct 1404 ms 236860 KB Output is correct
22 Correct 1267 ms 236976 KB Output is correct
23 Correct 1343 ms 236824 KB Output is correct
24 Correct 1458 ms 236736 KB Output is correct
25 Correct 1341 ms 236896 KB Output is correct
26 Correct 1300 ms 236776 KB Output is correct
27 Correct 1298 ms 236728 KB Output is correct
28 Correct 1243 ms 236864 KB Output is correct
29 Correct 1260 ms 236876 KB Output is correct
30 Correct 1307 ms 237052 KB Output is correct