답안 #685290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685290 2023-01-24T01:07:02 Z izanbf Examination (JOI19_examination) C++14
100 / 100
384 ms 28120 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define endl "\n"
//~ #define int long long
 
typedef long long int ll;
 
const int MOD = 1e9 + 7;
const int maxN = 200000;
 
bool cmp(pair<int, int> a, pair<int, int> b){
    return a.first + a.second > b.first + b.second;
}
 
bool cmp2(tuple<int, int, int, int> a, tuple<int, int, int, int> b){
    return get<2>(a) > get<2>(b);
}
 
struct BIT {
    int* bit;
    int n;
 
    void init(int n_) {
        n = n_+1;
        bit = new int[n+1];
        fill(bit, bit+n+1, 0);
    }
 
    int sum(int r) {
        int sum = 0;
        for (; r > 0; r -= r&-r)
            sum += bit[r];
        return sum;
    }
     
    int sum(int l, int r) {
        return sum(r) - sum(l-1);
    }
     
    void add(int r, int delta) {
        for (++r; r <= n; r += r&-r)
            bit[r] += delta;
    }
};

 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int n, q; cin >> n >> q;
    vector<pair<int, int>> v(n);
    set<int> sa;
    set<int> sb;
    for(int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        v[i] = {x, y};
        sa.insert(x);
        sb.insert(y);
    }
    map<int, int> a;
    map<int, int> b;
    int curr = 1;
    for(auto x : sa){
        a[x] = curr;
        curr++;
    }
    BIT sta; sta.init(curr);
    int sza = curr;
    curr = 1;
    for(auto x : sb){
        b[x] = curr;
        curr++;
    }
    BIT stb; stb.init(curr);
    int szb = curr;
    sort(v.begin(), v.end(), cmp);
    vector<tuple<int, int, int, int>> queries(q);
    for(int i = 0; i < q; i++){
        int x, y, z; cin >> x >> y >> z;
        int nx = sza;
        auto it = a.lower_bound(x);
        if(it != a.end()) nx = (*it).second;
        int ny = szb;
        it = b.lower_bound(y);
        if(it != b.end()) ny = (*it).second;
        queries[i] = {nx, ny, max(z, x + y), i};
    }
    sort(queries.begin(), queries.end(), cmp2);
    vector<int> ans(q);
    curr = 0;
    for(int i = 0; i < q; i++){
        while(curr < n && v[curr].first + v[curr].second >= get<2>(queries[i])){
            sta.add(a[v[curr].first], 1);
            stb.add(b[v[curr].second], 1);
            curr++;
        }
        int total = curr - sta.sum(1, get<0>(queries[i])) - stb.sum(1, get<1>(queries[i]));
        ans[get<3>(queries[i])] = total;
    }
    for(int x : ans) cout << x << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 1104 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 1108 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 6 ms 724 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 18356 KB Output is correct
2 Correct 259 ms 18468 KB Output is correct
3 Correct 307 ms 18556 KB Output is correct
4 Correct 135 ms 11464 KB Output is correct
5 Correct 134 ms 11524 KB Output is correct
6 Correct 61 ms 4540 KB Output is correct
7 Correct 245 ms 18288 KB Output is correct
8 Correct 225 ms 18332 KB Output is correct
9 Correct 243 ms 18256 KB Output is correct
10 Correct 129 ms 11356 KB Output is correct
11 Correct 126 ms 11368 KB Output is correct
12 Correct 48 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 18356 KB Output is correct
2 Correct 259 ms 18468 KB Output is correct
3 Correct 307 ms 18556 KB Output is correct
4 Correct 135 ms 11464 KB Output is correct
5 Correct 134 ms 11524 KB Output is correct
6 Correct 61 ms 4540 KB Output is correct
7 Correct 245 ms 18288 KB Output is correct
8 Correct 225 ms 18332 KB Output is correct
9 Correct 243 ms 18256 KB Output is correct
10 Correct 129 ms 11356 KB Output is correct
11 Correct 126 ms 11368 KB Output is correct
12 Correct 48 ms 4216 KB Output is correct
13 Correct 318 ms 18916 KB Output is correct
14 Correct 234 ms 18860 KB Output is correct
15 Correct 255 ms 18372 KB Output is correct
16 Correct 145 ms 12012 KB Output is correct
17 Correct 139 ms 11908 KB Output is correct
18 Correct 57 ms 4552 KB Output is correct
19 Correct 266 ms 18820 KB Output is correct
20 Correct 280 ms 18892 KB Output is correct
21 Correct 229 ms 18840 KB Output is correct
22 Correct 129 ms 11332 KB Output is correct
23 Correct 132 ms 11324 KB Output is correct
24 Correct 46 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 1104 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 1108 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 6 ms 724 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 287 ms 18356 KB Output is correct
20 Correct 259 ms 18468 KB Output is correct
21 Correct 307 ms 18556 KB Output is correct
22 Correct 135 ms 11464 KB Output is correct
23 Correct 134 ms 11524 KB Output is correct
24 Correct 61 ms 4540 KB Output is correct
25 Correct 245 ms 18288 KB Output is correct
26 Correct 225 ms 18332 KB Output is correct
27 Correct 243 ms 18256 KB Output is correct
28 Correct 129 ms 11356 KB Output is correct
29 Correct 126 ms 11368 KB Output is correct
30 Correct 48 ms 4216 KB Output is correct
31 Correct 318 ms 18916 KB Output is correct
32 Correct 234 ms 18860 KB Output is correct
33 Correct 255 ms 18372 KB Output is correct
34 Correct 145 ms 12012 KB Output is correct
35 Correct 139 ms 11908 KB Output is correct
36 Correct 57 ms 4552 KB Output is correct
37 Correct 266 ms 18820 KB Output is correct
38 Correct 280 ms 18892 KB Output is correct
39 Correct 229 ms 18840 KB Output is correct
40 Correct 129 ms 11332 KB Output is correct
41 Correct 132 ms 11324 KB Output is correct
42 Correct 46 ms 4184 KB Output is correct
43 Correct 364 ms 28120 KB Output is correct
44 Correct 358 ms 28028 KB Output is correct
45 Correct 384 ms 28048 KB Output is correct
46 Correct 176 ms 16700 KB Output is correct
47 Correct 162 ms 16628 KB Output is correct
48 Correct 59 ms 4424 KB Output is correct
49 Correct 332 ms 27940 KB Output is correct
50 Correct 344 ms 27888 KB Output is correct
51 Correct 322 ms 27808 KB Output is correct
52 Correct 159 ms 16404 KB Output is correct
53 Correct 163 ms 15692 KB Output is correct