답안 #1080538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080538 2024-08-29T10:49:47 Z batsukh2006 Index (COCI21_index) C++17
110 / 110
2309 ms 48684 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])){
      |                              ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20060 KB Output is correct
2 Correct 10 ms 19956 KB Output is correct
3 Correct 10 ms 19932 KB Output is correct
4 Correct 12 ms 20060 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 13 ms 20060 KB Output is correct
7 Correct 11 ms 20060 KB Output is correct
8 Correct 11 ms 20060 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 11 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20060 KB Output is correct
2 Correct 10 ms 19956 KB Output is correct
3 Correct 10 ms 19932 KB Output is correct
4 Correct 12 ms 20060 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 13 ms 20060 KB Output is correct
7 Correct 11 ms 20060 KB Output is correct
8 Correct 11 ms 20060 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 11 ms 20060 KB Output is correct
11 Correct 369 ms 26600 KB Output is correct
12 Correct 378 ms 26576 KB Output is correct
13 Correct 382 ms 26652 KB Output is correct
14 Correct 386 ms 26452 KB Output is correct
15 Correct 387 ms 26644 KB Output is correct
16 Correct 379 ms 26552 KB Output is correct
17 Correct 381 ms 26608 KB Output is correct
18 Correct 367 ms 26616 KB Output is correct
19 Correct 367 ms 26448 KB Output is correct
20 Correct 397 ms 26580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20060 KB Output is correct
2 Correct 10 ms 19956 KB Output is correct
3 Correct 10 ms 19932 KB Output is correct
4 Correct 12 ms 20060 KB Output is correct
5 Correct 10 ms 20060 KB Output is correct
6 Correct 13 ms 20060 KB Output is correct
7 Correct 11 ms 20060 KB Output is correct
8 Correct 11 ms 20060 KB Output is correct
9 Correct 11 ms 20060 KB Output is correct
10 Correct 11 ms 20060 KB Output is correct
11 Correct 369 ms 26600 KB Output is correct
12 Correct 378 ms 26576 KB Output is correct
13 Correct 382 ms 26652 KB Output is correct
14 Correct 386 ms 26452 KB Output is correct
15 Correct 387 ms 26644 KB Output is correct
16 Correct 379 ms 26552 KB Output is correct
17 Correct 381 ms 26608 KB Output is correct
18 Correct 367 ms 26616 KB Output is correct
19 Correct 367 ms 26448 KB Output is correct
20 Correct 397 ms 26580 KB Output is correct
21 Correct 2213 ms 48664 KB Output is correct
22 Correct 2300 ms 48444 KB Output is correct
23 Correct 2267 ms 48684 KB Output is correct
24 Correct 2285 ms 48464 KB Output is correct
25 Correct 2309 ms 48604 KB Output is correct
26 Correct 2249 ms 48464 KB Output is correct
27 Correct 2258 ms 48464 KB Output is correct
28 Correct 2269 ms 48464 KB Output is correct
29 Correct 2224 ms 48540 KB Output is correct
30 Correct 2291 ms 48484 KB Output is correct