Submission #1071712

# Submission time Handle Problem Language Result Execution time Memory
1071712 2024-08-23T10:22:07 Z Kevin_Jao Index (COCI21_index) C++14
110 / 110
2278 ms 48620 KB
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<math.h>
#include<vector>
#include<stdio.h>
#include<utility>
#include<iomanip>
#include<string.h>
#include<limits.h>
#include<algorithm>
#include<functional>
#include<unordered_map> 
using namespace std;
#pragma GCC target("popcnt")
#define MOD 1000000007
// #define int long long
#define ss second
#define ff first
#define endl '\n'
const int mxN=2e5+1;
vector<int> a(mxN),v[4*mxN];
void merge(int node){
    int i=0,j=0;
    v[node].reserve(v[node*2].size()+v[node*2+1].size());
	while(i<v[node*2].size()||j<v[node*2+1].size()){
		if(j==v[node*2+1].size()||(i<v[node*2].size()&&v[node*2][i]<v[node*2+1][j])){
			v[node].push_back(v[node*2][i]);
			i++;
		}else{
            v[node].push_back(v[node*2+1][j]);  
			j++;
		}
	}
}
int sum(int node, int t){
    auto r=v[node].size();
    auto l=lower_bound(v[node].begin(),v[node].end(),t)-v[node].begin();
    return r-l;
}
void build(int node, int L, int R){
    if(L==R){
        v[node].push_back(a[L]);
        return;
    }
    build(node*2,L,(L+R)/2);
    build(node*2+1,(L+R)/2+1,R);
    merge(node);
}
int cal(int node, int L, int R, int l, int r, int d){
    if(L>r||R<l) return 0;
    if(L>=l&&R<=r) return sum(node,d);
    return cal(node*2,L,(L+R)/2,l,r,d)+cal(node*2+1,(L+R)/2+1,R,l,r,d);
}
void solve(){
    int n,q; cin>>n>>q;
    int mx=0;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        mx=max(mx,a[i]);
    }
    build(1,1,n);
    while(q--){
        int lt,rt; cin>>lt>>rt;
        int l=1,r=mx;
        while(l<=r){
            int m=l+(r-l)/2;
            if(cal(1,1,n,lt,rt,m)>=m){
                l=m+1;
            }else{
                r=m-1;
            }
        }
        cout<<l-1<<endl;
    }
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T=1;
    // cin>>T;
    while(T--){
        solve();
        cout<<endl;
    }
	return 0;
}

Compilation message

index.cpp: In function 'void merge(int)':
index.cpp:31:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  while(i<v[node*2].size()||j<v[node*2+1].size()){
      |        ~^~~~~~~~~~~~~~~~~
index.cpp:31:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  while(i<v[node*2].size()||j<v[node*2+1].size()){
      |                            ~^~~~~~~~~~~~~~~~~~~
index.cpp:32:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   if(j==v[node*2+1].size()||(i<v[node*2].size()&&v[node*2][i]<v[node*2+1][j])){
      |      ~^~~~~~~~~~~~~~~~~~~~
index.cpp:32:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   if(j==v[node*2+1].size()||(i<v[node*2].size()&&v[node*2][i]<v[node*2+1][j])){
      |                              ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 20060 KB Output is correct
2 Correct 6 ms 20060 KB Output is correct
3 Correct 5 ms 20060 KB Output is correct
4 Correct 6 ms 20060 KB Output is correct
5 Correct 6 ms 20128 KB Output is correct
6 Correct 6 ms 20060 KB Output is correct
7 Correct 6 ms 20060 KB Output is correct
8 Correct 5 ms 20060 KB Output is correct
9 Correct 5 ms 20056 KB Output is correct
10 Correct 6 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 20060 KB Output is correct
2 Correct 6 ms 20060 KB Output is correct
3 Correct 5 ms 20060 KB Output is correct
4 Correct 6 ms 20060 KB Output is correct
5 Correct 6 ms 20128 KB Output is correct
6 Correct 6 ms 20060 KB Output is correct
7 Correct 6 ms 20060 KB Output is correct
8 Correct 5 ms 20060 KB Output is correct
9 Correct 5 ms 20056 KB Output is correct
10 Correct 6 ms 20060 KB Output is correct
11 Correct 370 ms 26656 KB Output is correct
12 Correct 374 ms 26456 KB Output is correct
13 Correct 361 ms 26452 KB Output is correct
14 Correct 387 ms 26616 KB Output is correct
15 Correct 366 ms 26452 KB Output is correct
16 Correct 384 ms 26632 KB Output is correct
17 Correct 377 ms 26620 KB Output is correct
18 Correct 368 ms 26452 KB Output is correct
19 Correct 361 ms 26500 KB Output is correct
20 Correct 375 ms 26452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 20060 KB Output is correct
2 Correct 6 ms 20060 KB Output is correct
3 Correct 5 ms 20060 KB Output is correct
4 Correct 6 ms 20060 KB Output is correct
5 Correct 6 ms 20128 KB Output is correct
6 Correct 6 ms 20060 KB Output is correct
7 Correct 6 ms 20060 KB Output is correct
8 Correct 5 ms 20060 KB Output is correct
9 Correct 5 ms 20056 KB Output is correct
10 Correct 6 ms 20060 KB Output is correct
11 Correct 370 ms 26656 KB Output is correct
12 Correct 374 ms 26456 KB Output is correct
13 Correct 361 ms 26452 KB Output is correct
14 Correct 387 ms 26616 KB Output is correct
15 Correct 366 ms 26452 KB Output is correct
16 Correct 384 ms 26632 KB Output is correct
17 Correct 377 ms 26620 KB Output is correct
18 Correct 368 ms 26452 KB Output is correct
19 Correct 361 ms 26500 KB Output is correct
20 Correct 375 ms 26452 KB Output is correct
21 Correct 2184 ms 48460 KB Output is correct
22 Correct 2231 ms 48496 KB Output is correct
23 Correct 2211 ms 48468 KB Output is correct
24 Correct 2205 ms 48516 KB Output is correct
25 Correct 2198 ms 48620 KB Output is correct
26 Correct 2258 ms 48464 KB Output is correct
27 Correct 2278 ms 48460 KB Output is correct
28 Correct 2223 ms 48512 KB Output is correct
29 Correct 2236 ms 48484 KB Output is correct
30 Correct 2214 ms 48496 KB Output is correct