Submission #970239

# Submission time Handle Problem Language Result Execution time Memory
970239 2024-04-26T09:09:41 Z blacktulip Index (COCI21_index) C++17
0 / 110
4 ms 1628 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 Incorrect 4 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -