답안 #1097730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097730 2024-10-08T04:43:18 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
479 ms 61136 KB
#include <bits/stdc++.h>

#define ll long long

using namespace std;
const int N = 1e5  + 2;
// int num_node = 0;
int n , q , m;
pair < ll , ll > a[N + 2];
vector < ll > vt; 
bool cmp_1(pair < int , int > g , pair < int , int > h){
    return g.first < h.first;
}
bool cmp_2(pair < int , int > g , pair < int , int > h){
    return g.first < h.first;
}
struct per{
    vector <pair < int , int > > bit[N * 4 + 2];
    void update(int id , int timer){
        while(id <= m){
            if(bit[id].empty())bit[id].push_back({timer , 1});
            else{
                int cur = bit[id].back().second;
                bit[id].push_back({timer , cur + 1});
            }
            id += id &(-id);
        }
    }
    int get(int id , int timer){
        int ans = 0;
        while(id  > 0){
            if(bit[id].size()){
                int k = upper_bound(bit[id].begin() , bit[id].end() , make_pair(timer , 0), cmp_1) - bit[id].begin();
                k--;
                if(k >= 0){
                    ans += bit[id][k].second;
                }
            }
            id -= id &(-id);
        }
        return ans;
    }
}BIT_ONE ,BIT_TWO;
int get_one(ll l , int timer_l , int timer_r){
    int k = upper_bound(vt.begin() , vt.end() , l) - vt.begin();
    if(k == 0)return 0;
   return  BIT_ONE.get(m , timer_r) - BIT_ONE.get(k - 1 , timer_r) + BIT_ONE.get(k - 1 , timer_l - 1) - BIT_ONE.get(m , timer_l - 1);
}
int get_two(ll c , int timer_l , int timer_r){
    int k = upper_bound(vt.begin() , vt.end() , c) - vt.begin();
     if(k == 0)return 0;
    return BIT_TWO.get(m , timer_r) - BIT_TWO.get(k - 1 , timer_r) + BIT_TWO.get(k - 1 , timer_l - 1) - BIT_TWO.get(m , timer_l - 1);
}
struct qq{
    ll t , c;
    int id;
};
vector < qq > query[N + 2];
int ans[N + 2];
void pre(){
        for(int  i= 1; i <= n ; i ++){
            vt.push_back(a[i].second);
            vt.push_back(a[i].first + a[i].second);
        }
        sort(vt.begin() , vt.end());
        vt.erase(unique(vt.begin() , vt.end()) , vt.end());
        m= vt.size();
        for(int i = 1 ; i <= n; i ++){
            int k = upper_bound(vt.begin() , vt.end() , a[i].second) - vt.begin();
            BIT_ONE.update(k , i);
            k = upper_bound(vt.begin() , vt.end() , a[i].first + a[i].second)- vt.begin();
            BIT_TWO.update(k , i);
          //  cout << get_two(100 , 1 , n) << ' ';
        }
       // for(auto v: vt)cout <<v << ' ';
       // cout << BIT_ONE.get(m , n) -BIT_ONE.get(k - 1 , n) <<  '\n';
       // cout <<'\n';
}
int bin(ll t , ll c , int i){
    int l = i;
    int r = n ;
    while(l <= r){
        int mid = (l + r) / 2;
        if(c - a[mid].first >= t){
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return l  - 1;

}
void solve() {
    cin >> n >> q;
    for(int i = 1; i <= n ; i ++){
        cin >> a[i].first >> a[i].second;
    }
    sort(a  + 1 , a + n + 1);
    for(int i = 1 ; i <= q ; i ++){
        ll s ,  t , c;
        cin >> s >> t >> c;
       int k = lower_bound(a +  1 , a + n + 1, make_pair(s , 0), cmp_2)  - a; 
        query[k].push_back({t , c , i});
        vt.push_back(t);
        vt.push_back(c);
       
    }
      pre();
    for(int  i =n ;i >= 1; i --){
        for(auto cur : query[i]){
            int kl = bin(cur.t , cur.c , i);
            if(kl >= i){
                ans[cur.id] += get_two(cur.c , i , kl);
            }
            if(kl < n){
                ans[cur.id] += get_one(cur.t , kl + 1 , n);
            }
        }
    }
    for(int  i = 1 ; i <= q; i ++){
        cout << ans[i] << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "examination"
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21596 KB Output is correct
2 Correct 14 ms 21852 KB Output is correct
3 Correct 10 ms 21596 KB Output is correct
4 Correct 9 ms 21528 KB Output is correct
5 Correct 9 ms 21424 KB Output is correct
6 Correct 10 ms 21596 KB Output is correct
7 Correct 16 ms 22560 KB Output is correct
8 Correct 16 ms 22616 KB Output is correct
9 Correct 17 ms 22620 KB Output is correct
10 Correct 15 ms 22620 KB Output is correct
11 Correct 14 ms 22672 KB Output is correct
12 Correct 12 ms 21980 KB Output is correct
13 Correct 14 ms 22360 KB Output is correct
14 Correct 15 ms 22360 KB Output is correct
15 Correct 16 ms 22364 KB Output is correct
16 Correct 13 ms 22364 KB Output is correct
17 Correct 12 ms 22620 KB Output is correct
18 Correct 10 ms 22108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 53428 KB Output is correct
2 Correct 275 ms 53600 KB Output is correct
3 Correct 243 ms 53684 KB Output is correct
4 Correct 128 ms 53940 KB Output is correct
5 Correct 187 ms 53684 KB Output is correct
6 Correct 79 ms 38208 KB Output is correct
7 Correct 221 ms 53684 KB Output is correct
8 Correct 229 ms 53088 KB Output is correct
9 Correct 203 ms 53172 KB Output is correct
10 Correct 138 ms 51848 KB Output is correct
11 Correct 132 ms 55176 KB Output is correct
12 Correct 58 ms 37500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 53428 KB Output is correct
2 Correct 275 ms 53600 KB Output is correct
3 Correct 243 ms 53684 KB Output is correct
4 Correct 128 ms 53940 KB Output is correct
5 Correct 187 ms 53684 KB Output is correct
6 Correct 79 ms 38208 KB Output is correct
7 Correct 221 ms 53684 KB Output is correct
8 Correct 229 ms 53088 KB Output is correct
9 Correct 203 ms 53172 KB Output is correct
10 Correct 138 ms 51848 KB Output is correct
11 Correct 132 ms 55176 KB Output is correct
12 Correct 58 ms 37500 KB Output is correct
13 Correct 345 ms 55720 KB Output is correct
14 Correct 327 ms 55476 KB Output is correct
15 Correct 266 ms 53684 KB Output is correct
16 Correct 223 ms 57780 KB Output is correct
17 Correct 222 ms 53428 KB Output is correct
18 Correct 87 ms 38584 KB Output is correct
19 Correct 350 ms 55644 KB Output is correct
20 Correct 341 ms 55740 KB Output is correct
21 Correct 360 ms 55732 KB Output is correct
22 Correct 134 ms 52096 KB Output is correct
23 Correct 132 ms 54964 KB Output is correct
24 Correct 55 ms 37396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21596 KB Output is correct
2 Correct 14 ms 21852 KB Output is correct
3 Correct 10 ms 21596 KB Output is correct
4 Correct 9 ms 21528 KB Output is correct
5 Correct 9 ms 21424 KB Output is correct
6 Correct 10 ms 21596 KB Output is correct
7 Correct 16 ms 22560 KB Output is correct
8 Correct 16 ms 22616 KB Output is correct
9 Correct 17 ms 22620 KB Output is correct
10 Correct 15 ms 22620 KB Output is correct
11 Correct 14 ms 22672 KB Output is correct
12 Correct 12 ms 21980 KB Output is correct
13 Correct 14 ms 22360 KB Output is correct
14 Correct 15 ms 22360 KB Output is correct
15 Correct 16 ms 22364 KB Output is correct
16 Correct 13 ms 22364 KB Output is correct
17 Correct 12 ms 22620 KB Output is correct
18 Correct 10 ms 22108 KB Output is correct
19 Correct 248 ms 53428 KB Output is correct
20 Correct 275 ms 53600 KB Output is correct
21 Correct 243 ms 53684 KB Output is correct
22 Correct 128 ms 53940 KB Output is correct
23 Correct 187 ms 53684 KB Output is correct
24 Correct 79 ms 38208 KB Output is correct
25 Correct 221 ms 53684 KB Output is correct
26 Correct 229 ms 53088 KB Output is correct
27 Correct 203 ms 53172 KB Output is correct
28 Correct 138 ms 51848 KB Output is correct
29 Correct 132 ms 55176 KB Output is correct
30 Correct 58 ms 37500 KB Output is correct
31 Correct 345 ms 55720 KB Output is correct
32 Correct 327 ms 55476 KB Output is correct
33 Correct 266 ms 53684 KB Output is correct
34 Correct 223 ms 57780 KB Output is correct
35 Correct 222 ms 53428 KB Output is correct
36 Correct 87 ms 38584 KB Output is correct
37 Correct 350 ms 55644 KB Output is correct
38 Correct 341 ms 55740 KB Output is correct
39 Correct 360 ms 55732 KB Output is correct
40 Correct 134 ms 52096 KB Output is correct
41 Correct 132 ms 54964 KB Output is correct
42 Correct 55 ms 37396 KB Output is correct
43 Correct 416 ms 60920 KB Output is correct
44 Correct 414 ms 60948 KB Output is correct
45 Correct 376 ms 60084 KB Output is correct
46 Correct 246 ms 60624 KB Output is correct
47 Correct 287 ms 61136 KB Output is correct
48 Correct 82 ms 40124 KB Output is correct
49 Correct 435 ms 59800 KB Output is correct
50 Correct 387 ms 59832 KB Output is correct
51 Correct 479 ms 58804 KB Output is correct
52 Correct 178 ms 58220 KB Output is correct
53 Correct 147 ms 57396 KB Output is correct