답안 #897227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897227 2024-01-02T18:37:38 Z MarwenElarbi Examination (JOI19_examination) C++17
100 / 100
523 ms 52428 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 1e5+5;
const int lg = 20;
struct student{
    int sum, left, right;
};
int n,q;
vector<student> tab(nax);
vector<int> segtree[nax*4][2];
int bs(int cur){
    int l=-1;
    int r=n;
    while(r-l>1){
        int mid=(r+l)/2;
        if(tab[mid].sum>=cur) r=mid;
        else l=mid;
    }
    return r;
}
void build(int pos,int l,int r,int idx){
    if(l==r){
        if(idx==0) segtree[pos][idx].pb(tab[l].left);
        else segtree[pos][idx].pb(tab[l].right);
        return;
    }
    int mid=(l+r)/2;
    build(pos*2+1,l,mid,idx);
    build(pos*2+2,mid+1,r,idx);
    int j=0;
    for (int i = 0; i < segtree[pos*2+1][idx].size(); ++i)
    {
        while(j<segtree[pos*2+2][idx].size()&&segtree[pos*2+2][idx][j]<segtree[pos*2+1][idx][i]) segtree[pos][idx].pb(segtree[pos*2+2][idx][j++]);
        segtree[pos][idx].pb(segtree[pos*2+1][idx][i]);
    }
    while(j<segtree[pos*2+2][idx].size()) segtree[pos][idx].pb(segtree[pos*2+2][idx][j++]);
    return;
}
int query(int pos,int l,int r,int left,int right,int idx,int value){
    if(l>r||l>right||r<left) return 0;
    if(l>=left&&r<=right){
        int lefty=-1;
        int righty=segtree[pos][idx].size();
        while(righty-lefty>1){
            int middle=(lefty+righty)/2;
            //cout <<segtree[pos][idx][middle]<<endl;
            if(segtree[pos][idx][middle]<value) lefty=middle;
            else righty=middle;
        }
        //cout <<l<<" "<<r<<" "<<lefty<<endl;
        return lefty+1;
    }
    int mid=(r+l)/2;
    return query(pos*2+1,l,mid,left,right,idx,value)+query(pos*2+2,mid+1,r,left,right,idx,value);
}
int main() {
    optimise;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    cin>>n>>q;
    tab.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i].left>>tab[i].right;
        tab[i].sum=tab[i].left+tab[i].right;
    }
    auto cmp=[&](student a,student b){
        return a.sum<b.sum;
    };
    sort(tab.begin(),tab.end(),cmp);
    build(0,0,n-1,0);
    build(0,0,n-1,1);
    /*for (int i = 0; i < tab.size(); ++i)
    {
        cout<<tab[i].sum<<" "<<tab[i].left<<" "<<tab[i].right<<endl;
    }*/
    while(q--){
        int a,b,c;
        cin>>a>>b>>c;
        int idx=bs(max(c,a+b));
        if(idx==n){
            cout << 0<<endl;
            continue;
        }
        int x=query(0,0,n-1,idx,n-1,0,a)+query(0,0,n-1,idx,n-1,1,b);
        //cout <<idx<<" "<<x<<endl;
        cout << n-idx-x<<endl;
    }
}

Compilation message

examination.cpp: In function 'void build(int, int, int, int)':
examination.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < segtree[pos*2+1][idx].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while(j<segtree[pos*2+2][idx].size()&&segtree[pos*2+2][idx][j]<segtree[pos*2+1][idx][i]) segtree[pos][idx].pb(segtree[pos*2+2][idx][j++]);
      |               ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:57:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     while(j<segtree[pos*2+2][idx].size()) segtree[pos][idx].pb(segtree[pos*2+2][idx][j++]);
      |           ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20316 KB Output is correct
2 Correct 5 ms 20316 KB Output is correct
3 Correct 5 ms 20316 KB Output is correct
4 Correct 5 ms 20316 KB Output is correct
5 Correct 5 ms 20316 KB Output is correct
6 Correct 5 ms 20316 KB Output is correct
7 Correct 13 ms 21084 KB Output is correct
8 Correct 13 ms 21084 KB Output is correct
9 Correct 13 ms 21080 KB Output is correct
10 Correct 12 ms 21084 KB Output is correct
11 Correct 16 ms 21084 KB Output is correct
12 Correct 12 ms 21084 KB Output is correct
13 Correct 14 ms 21084 KB Output is correct
14 Correct 13 ms 21084 KB Output is correct
15 Correct 13 ms 21084 KB Output is correct
16 Correct 12 ms 21084 KB Output is correct
17 Correct 14 ms 21116 KB Output is correct
18 Correct 10 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 48372 KB Output is correct
2 Correct 481 ms 49868 KB Output is correct
3 Correct 444 ms 49684 KB Output is correct
4 Correct 431 ms 49352 KB Output is correct
5 Correct 487 ms 49164 KB Output is correct
6 Correct 363 ms 48588 KB Output is correct
7 Correct 426 ms 49828 KB Output is correct
8 Correct 434 ms 49992 KB Output is correct
9 Correct 395 ms 49696 KB Output is correct
10 Correct 399 ms 48728 KB Output is correct
11 Correct 417 ms 49084 KB Output is correct
12 Correct 214 ms 47816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 48372 KB Output is correct
2 Correct 481 ms 49868 KB Output is correct
3 Correct 444 ms 49684 KB Output is correct
4 Correct 431 ms 49352 KB Output is correct
5 Correct 487 ms 49164 KB Output is correct
6 Correct 363 ms 48588 KB Output is correct
7 Correct 426 ms 49828 KB Output is correct
8 Correct 434 ms 49992 KB Output is correct
9 Correct 395 ms 49696 KB Output is correct
10 Correct 399 ms 48728 KB Output is correct
11 Correct 417 ms 49084 KB Output is correct
12 Correct 214 ms 47816 KB Output is correct
13 Correct 422 ms 50432 KB Output is correct
14 Correct 513 ms 50040 KB Output is correct
15 Correct 523 ms 50056 KB Output is correct
16 Correct 400 ms 49352 KB Output is correct
17 Correct 400 ms 49388 KB Output is correct
18 Correct 382 ms 48328 KB Output is correct
19 Correct 431 ms 50156 KB Output is correct
20 Correct 466 ms 50352 KB Output is correct
21 Correct 427 ms 50216 KB Output is correct
22 Correct 405 ms 48844 KB Output is correct
23 Correct 409 ms 49100 KB Output is correct
24 Correct 209 ms 48108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20316 KB Output is correct
2 Correct 5 ms 20316 KB Output is correct
3 Correct 5 ms 20316 KB Output is correct
4 Correct 5 ms 20316 KB Output is correct
5 Correct 5 ms 20316 KB Output is correct
6 Correct 5 ms 20316 KB Output is correct
7 Correct 13 ms 21084 KB Output is correct
8 Correct 13 ms 21084 KB Output is correct
9 Correct 13 ms 21080 KB Output is correct
10 Correct 12 ms 21084 KB Output is correct
11 Correct 16 ms 21084 KB Output is correct
12 Correct 12 ms 21084 KB Output is correct
13 Correct 14 ms 21084 KB Output is correct
14 Correct 13 ms 21084 KB Output is correct
15 Correct 13 ms 21084 KB Output is correct
16 Correct 12 ms 21084 KB Output is correct
17 Correct 14 ms 21116 KB Output is correct
18 Correct 10 ms 21084 KB Output is correct
19 Correct 480 ms 48372 KB Output is correct
20 Correct 481 ms 49868 KB Output is correct
21 Correct 444 ms 49684 KB Output is correct
22 Correct 431 ms 49352 KB Output is correct
23 Correct 487 ms 49164 KB Output is correct
24 Correct 363 ms 48588 KB Output is correct
25 Correct 426 ms 49828 KB Output is correct
26 Correct 434 ms 49992 KB Output is correct
27 Correct 395 ms 49696 KB Output is correct
28 Correct 399 ms 48728 KB Output is correct
29 Correct 417 ms 49084 KB Output is correct
30 Correct 214 ms 47816 KB Output is correct
31 Correct 422 ms 50432 KB Output is correct
32 Correct 513 ms 50040 KB Output is correct
33 Correct 523 ms 50056 KB Output is correct
34 Correct 400 ms 49352 KB Output is correct
35 Correct 400 ms 49388 KB Output is correct
36 Correct 382 ms 48328 KB Output is correct
37 Correct 431 ms 50156 KB Output is correct
38 Correct 466 ms 50352 KB Output is correct
39 Correct 427 ms 50216 KB Output is correct
40 Correct 405 ms 48844 KB Output is correct
41 Correct 409 ms 49100 KB Output is correct
42 Correct 209 ms 48108 KB Output is correct
43 Correct 486 ms 52140 KB Output is correct
44 Correct 423 ms 52024 KB Output is correct
45 Correct 460 ms 52428 KB Output is correct
46 Correct 436 ms 50464 KB Output is correct
47 Correct 431 ms 50940 KB Output is correct
48 Correct 248 ms 48216 KB Output is correct
49 Correct 479 ms 52040 KB Output is correct
50 Correct 448 ms 52168 KB Output is correct
51 Correct 426 ms 52020 KB Output is correct
52 Correct 403 ms 50552 KB Output is correct
53 Correct 412 ms 49868 KB Output is correct