답안 #297946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297946 2020-09-12T08:11:13 Z b00n0rp Examination (JOI19_examination) C++17
100 / 100
2571 ms 143500 KB
#include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define pii pair<int,int>
#define F first
#define S second

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int MX = 200005;

int n,q;

pair<pii,pii> a[MX],quer[MX];
int ans[MX];

indexed_set seg[2*MX];

int SZ = 0;

void upd(int pos,int val){
    pos += SZ;
    while(pos){
        seg[pos].insert(val);
        pos /= 2;
    }
}

int query(int l,int val){
    l += SZ;
    int r = 2*SZ;
    int res = 0;
    while(l < r){
        if(l%2){
            res += seg[l].size()-seg[l].order_of_key(val);
            l++;
        }
        if(r%2){
            --r;
            res += seg[r].size()-seg[r].order_of_key(val);
        }
        l /= 2;
        r /= 2;
    }
    return res;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> q;
    
    set<int> s;
    map<int,int> m;

    REP(i,n){
        cin >> a[i].S.F >> a[i].S.S;
        a[i].F.F = a[i].S.F+a[i].S.S;
        a[i].F.S = i;
        s.insert(a[i].S.F);
    }
    sort(a,a+n);
    REP(i,q){
        cin >> quer[i].S.F >> quer[i].S.S >> quer[i].F.F;
        quer[i].F.F = max(quer[i].F.F,quer[i].S.F+quer[i].S.S);
        s.insert(quer[i].S.F);
        quer[i].F.S = i;
    }
    sort(quer,quer+q);
    
    for(auto x:s){
        m[x] = SZ++;
    }
    REP(i,n) a[i].S.F = m[a[i].S.F];
    REP(i,q) quer[i].S.F = m[quer[i].S.F];
    int ind = n-1;
    for(int i = q-1; i >= 0; i --){
        while(ind >= 0 and a[ind].F.F >= quer[i].F.F){
            upd(a[ind].S.F,a[ind].S.S);
            ind--;
        }
        ans[quer[i].F.S] = query(quer[i].S.F,quer[i].S.S);
    }
    REP(i,q) cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 31608 KB Output is correct
2 Correct 34 ms 31744 KB Output is correct
3 Correct 33 ms 31616 KB Output is correct
4 Correct 37 ms 31616 KB Output is correct
5 Correct 35 ms 31608 KB Output is correct
6 Correct 34 ms 31608 KB Output is correct
7 Correct 50 ms 34296 KB Output is correct
8 Correct 52 ms 34296 KB Output is correct
9 Correct 52 ms 34296 KB Output is correct
10 Correct 50 ms 34296 KB Output is correct
11 Correct 40 ms 32384 KB Output is correct
12 Correct 40 ms 32376 KB Output is correct
13 Correct 52 ms 34296 KB Output is correct
14 Correct 50 ms 34296 KB Output is correct
15 Correct 54 ms 34428 KB Output is correct
16 Correct 38 ms 32120 KB Output is correct
17 Correct 50 ms 34296 KB Output is correct
18 Correct 37 ms 32248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2361 ms 126048 KB Output is correct
2 Correct 2415 ms 126072 KB Output is correct
3 Correct 2364 ms 126176 KB Output is correct
4 Correct 1219 ms 125944 KB Output is correct
5 Correct 390 ms 57080 KB Output is correct
6 Correct 374 ms 57080 KB Output is correct
7 Correct 2259 ms 122232 KB Output is correct
8 Correct 2168 ms 126200 KB Output is correct
9 Correct 2007 ms 122148 KB Output is correct
10 Correct 186 ms 45048 KB Output is correct
11 Correct 1020 ms 125828 KB Output is correct
12 Correct 284 ms 49528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2361 ms 126048 KB Output is correct
2 Correct 2415 ms 126072 KB Output is correct
3 Correct 2364 ms 126176 KB Output is correct
4 Correct 1219 ms 125944 KB Output is correct
5 Correct 390 ms 57080 KB Output is correct
6 Correct 374 ms 57080 KB Output is correct
7 Correct 2259 ms 122232 KB Output is correct
8 Correct 2168 ms 126200 KB Output is correct
9 Correct 2007 ms 122148 KB Output is correct
10 Correct 186 ms 45048 KB Output is correct
11 Correct 1020 ms 125828 KB Output is correct
12 Correct 284 ms 49528 KB Output is correct
13 Correct 2168 ms 126076 KB Output is correct
14 Correct 2405 ms 126212 KB Output is correct
15 Correct 2374 ms 125928 KB Output is correct
16 Correct 1186 ms 126072 KB Output is correct
17 Correct 383 ms 56952 KB Output is correct
18 Correct 377 ms 57292 KB Output is correct
19 Correct 2147 ms 126072 KB Output is correct
20 Correct 2308 ms 126072 KB Output is correct
21 Correct 2161 ms 125176 KB Output is correct
22 Correct 181 ms 44924 KB Output is correct
23 Correct 1028 ms 125816 KB Output is correct
24 Correct 278 ms 49528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 31608 KB Output is correct
2 Correct 34 ms 31744 KB Output is correct
3 Correct 33 ms 31616 KB Output is correct
4 Correct 37 ms 31616 KB Output is correct
5 Correct 35 ms 31608 KB Output is correct
6 Correct 34 ms 31608 KB Output is correct
7 Correct 50 ms 34296 KB Output is correct
8 Correct 52 ms 34296 KB Output is correct
9 Correct 52 ms 34296 KB Output is correct
10 Correct 50 ms 34296 KB Output is correct
11 Correct 40 ms 32384 KB Output is correct
12 Correct 40 ms 32376 KB Output is correct
13 Correct 52 ms 34296 KB Output is correct
14 Correct 50 ms 34296 KB Output is correct
15 Correct 54 ms 34428 KB Output is correct
16 Correct 38 ms 32120 KB Output is correct
17 Correct 50 ms 34296 KB Output is correct
18 Correct 37 ms 32248 KB Output is correct
19 Correct 2361 ms 126048 KB Output is correct
20 Correct 2415 ms 126072 KB Output is correct
21 Correct 2364 ms 126176 KB Output is correct
22 Correct 1219 ms 125944 KB Output is correct
23 Correct 390 ms 57080 KB Output is correct
24 Correct 374 ms 57080 KB Output is correct
25 Correct 2259 ms 122232 KB Output is correct
26 Correct 2168 ms 126200 KB Output is correct
27 Correct 2007 ms 122148 KB Output is correct
28 Correct 186 ms 45048 KB Output is correct
29 Correct 1020 ms 125828 KB Output is correct
30 Correct 284 ms 49528 KB Output is correct
31 Correct 2168 ms 126076 KB Output is correct
32 Correct 2405 ms 126212 KB Output is correct
33 Correct 2374 ms 125928 KB Output is correct
34 Correct 1186 ms 126072 KB Output is correct
35 Correct 383 ms 56952 KB Output is correct
36 Correct 377 ms 57292 KB Output is correct
37 Correct 2147 ms 126072 KB Output is correct
38 Correct 2308 ms 126072 KB Output is correct
39 Correct 2161 ms 125176 KB Output is correct
40 Correct 181 ms 44924 KB Output is correct
41 Correct 1028 ms 125816 KB Output is correct
42 Correct 278 ms 49528 KB Output is correct
43 Correct 2430 ms 142200 KB Output is correct
44 Correct 2486 ms 142200 KB Output is correct
45 Correct 2571 ms 142456 KB Output is correct
46 Correct 1336 ms 142072 KB Output is correct
47 Correct 390 ms 57080 KB Output is correct
48 Correct 374 ms 56952 KB Output is correct
49 Correct 2560 ms 143480 KB Output is correct
50 Correct 2373 ms 142376 KB Output is correct
51 Correct 2353 ms 143500 KB Output is correct
52 Correct 258 ms 44920 KB Output is correct
53 Correct 1164 ms 142200 KB Output is correct