답안 #1046936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046936 2024-08-07T06:35:28 Z DangerNoodle7591 Index (COCI21_index) C++17
110 / 110
1161 ms 132032 KB
#include <bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int long long int
#define endl '\n'
#define N 200105
#define MM 200000
#define mod 1000000007
#define pb push_back
#define p push
#define ins insert
#define f first
#define s second

//persistent segment tree kodu ///////////////////////////////////////////////////////////////////////////////////////////////////
int n;
struct node{
	node *left, *right;
	int val;
	node(node* a,node* b){
		val=0;
		left=a;
		right=b;
		if(a) val+=a->val;
		if(b) val+=b->val;
	}
	node(){
		val=0;
		left=NULL;right=NULL;
	}
};

vector<node*> baslar;

node* update(node* x,int l,int r,int hed){
	if(l==r){
		node* yeni=new node;
		yeni->val=x->val+1;
		return yeni;
	}
	if(x->left==NULL)x->left=new node;
	if(x->right==NULL)x->right=new node;
	int mid=(l+r)/2;
	if(hed<=mid){
		return new node(update(x->left,l,mid,hed),x->right);
	}
	return new node(x->left,update(x->right,mid+1,r,hed));
	
}
inline int qua(node* x,int l,int r,int s,int e){
	if(l>r||s>r||e<l||x==NULL) return 0;
	if(s<=l&&r<=e)return x->val;
	int mid=(l+r)/2;
	return qua(x->left, l,mid,s,e)+qua(x->right,mid+1,r,s,e);
}
int cev(int x,int y){
	int l=1,r=n;
	int yes=-1;
	while(l<=r){
		int mid=(l+r)/2;
		int a=qua(baslar[x-1],1,MM,1,MM-mid+1);
		int b=qua(baslar[y],1,MM,1,MM-mid+1);
		//cout<<l<<" "<<r<<" "<<mid<<" "<<a<<" "<<b<<endl;
		if(b-a>=mid){
			yes=mid;
			l=mid+1;
		}
		else r=mid-1;

	}
	return yes;
}
signed main(){
	lalala;
	node* bas=new node;
	baslar.pb(bas);
	int q;cin>>n>>q;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		int y=MM-x+1;
		node* yeni=update(baslar[baslar.size()-1],1,MM,y);
		baslar.pb(yeni);
	}

	while(q--){
		int x,y;cin>>x>>y;
		cout<<cev(x,y)<<endl;
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 872 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 872 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 169 ms 33132 KB Output is correct
12 Correct 176 ms 33276 KB Output is correct
13 Correct 169 ms 33228 KB Output is correct
14 Correct 179 ms 33344 KB Output is correct
15 Correct 172 ms 33224 KB Output is correct
16 Correct 175 ms 33332 KB Output is correct
17 Correct 174 ms 33488 KB Output is correct
18 Correct 177 ms 33080 KB Output is correct
19 Correct 173 ms 33196 KB Output is correct
20 Correct 171 ms 33120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 872 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 169 ms 33132 KB Output is correct
12 Correct 176 ms 33276 KB Output is correct
13 Correct 169 ms 33228 KB Output is correct
14 Correct 179 ms 33344 KB Output is correct
15 Correct 172 ms 33224 KB Output is correct
16 Correct 175 ms 33332 KB Output is correct
17 Correct 174 ms 33488 KB Output is correct
18 Correct 177 ms 33080 KB Output is correct
19 Correct 173 ms 33196 KB Output is correct
20 Correct 171 ms 33120 KB Output is correct
21 Correct 1087 ms 132032 KB Output is correct
22 Correct 1079 ms 131804 KB Output is correct
23 Correct 1114 ms 131856 KB Output is correct
24 Correct 1073 ms 131772 KB Output is correct
25 Correct 1096 ms 131772 KB Output is correct
26 Correct 1161 ms 131772 KB Output is correct
27 Correct 1070 ms 131912 KB Output is correct
28 Correct 1084 ms 131768 KB Output is correct
29 Correct 1092 ms 131788 KB Output is correct
30 Correct 1101 ms 131912 KB Output is correct