답안 #452115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
452115 2021-08-03T19:36:26 Z JovanB Examination (JOI19_examination) C++17
100 / 100
872 ms 54064 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
struct BIT{
    int n;
    int val[1000000];
    int get(int x){
        int res = 0;
        while(x){
            res += val[x];
            x -= x & -x;
        }
        return res;
    }
    void add(int x, int vrd){
        while(x <= n){
            val[x] += vrd;
            x += x & -x;
        }
    }
};
 
struct query{
    int x, y, z, ind;
};
 
bool cmp1(query a, query b){
    if(a.x == b.x) return a.ind > b.ind;
    return a.x < b.x;
}
 
bool cmp2(query a, query b){
    if(a.z == b.z) return a.ind > b.ind;
    return a.z < b.z;
}
 
pair <int, int> niz[100005];
map <int, int> compr;
int tcomp;
query queries1[200005], queries2[200005];
int res[100005];
 
int main(){
    ios_base::sync_with_stdio(false);
 
    int n, q;
    cin >> n >> q;
    vector <int> compvec;
    for(int i=1; i<=n; i++){
        cin >> niz[i].first >> niz[i].second;
        compvec.push_back(niz[i].first);
        compvec.push_back(niz[i].second);
        compvec.push_back(niz[i].first+niz[i].second);
    }
    int q1 = 0, q2 = 0;
    for(int i=1; i<=q; i++){
        int x, y, z;
        cin >> x >> y >> z;
        compvec.push_back(x);
        compvec.push_back(y);
        compvec.push_back(z);
        query tq;
        tq.x = x, tq.y = y, tq.z = z, tq.ind = i;
        if(z <= x+y) queries1[++q1] = tq;
        else queries2[++q2] = tq;
    }
    for(int i=1; i<=n; i++){
        query tq;
        tq.x = niz[i].first;
        tq.y = niz[i].second;
        tq.ind = tq.z = 0;
        queries1[++q1] = tq;
    }
    sort(compvec.begin(), compvec.end());
    for(auto c : compvec){
        if(!compr[c]) compr[c] = ++tcomp;
    }
    sort(queries1+1, queries1+1+q1, cmp1);
    int bilo = 0;
    BIT sam;
    sam.n = tcomp;
    for(int i=q1; i>=1; i--){
        if(queries1[i].ind == 0){
            bilo++;
            sam.add(compr[queries1[i].y], 1);
        }
        else{
            res[queries1[i].ind] += bilo - sam.get(compr[queries1[i].y]-1);
        }
    }
 
    for(int i=1; i<=n; i++){
        query tq;
        tq.x = niz[i].first;
        tq.y = niz[i].second;
        tq.z = niz[i].first + niz[i].second;
        tq.ind = 0;
        queries2[++q2] = tq;
    }
    sort(queries2+1, queries2+1+q2, cmp2);
    BIT prvo, drugo;
    bilo = 0;
    prvo.n = drugo.n = tcomp;
    for(int i=q2; i>=1; i--){
        if(queries2[i].ind == 0){
            bilo++;
            prvo.add(compr[queries2[i].x], 1);
            drugo.add(compr[queries2[i].y], 1);
        }
        else{
            res[queries2[i].ind] += bilo - prvo.get(compr[queries2[i].x]-1) - drugo.get(compr[queries2[i].y]-1);
        }
    }
    for(int i=1; i<=q; i++) cout << res[i] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
3 Correct 6 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 6 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 17 ms 13272 KB Output is correct
8 Correct 17 ms 13268 KB Output is correct
9 Correct 17 ms 13260 KB Output is correct
10 Correct 13 ms 12876 KB Output is correct
11 Correct 14 ms 12876 KB Output is correct
12 Correct 9 ms 12492 KB Output is correct
13 Correct 15 ms 13152 KB Output is correct
14 Correct 15 ms 13100 KB Output is correct
15 Correct 16 ms 13100 KB Output is correct
16 Correct 13 ms 12628 KB Output is correct
17 Correct 13 ms 12844 KB Output is correct
18 Correct 10 ms 12420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 29744 KB Output is correct
2 Correct 352 ms 29676 KB Output is correct
3 Correct 341 ms 29744 KB Output is correct
4 Correct 219 ms 26992 KB Output is correct
5 Correct 255 ms 27052 KB Output is correct
6 Correct 117 ms 22024 KB Output is correct
7 Correct 348 ms 29488 KB Output is correct
8 Correct 329 ms 29476 KB Output is correct
9 Correct 331 ms 29204 KB Output is correct
10 Correct 242 ms 26472 KB Output is correct
11 Correct 207 ms 26416 KB Output is correct
12 Correct 96 ms 21608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 29744 KB Output is correct
2 Correct 352 ms 29676 KB Output is correct
3 Correct 341 ms 29744 KB Output is correct
4 Correct 219 ms 26992 KB Output is correct
5 Correct 255 ms 27052 KB Output is correct
6 Correct 117 ms 22024 KB Output is correct
7 Correct 348 ms 29488 KB Output is correct
8 Correct 329 ms 29476 KB Output is correct
9 Correct 331 ms 29204 KB Output is correct
10 Correct 242 ms 26472 KB Output is correct
11 Correct 207 ms 26416 KB Output is correct
12 Correct 96 ms 21608 KB Output is correct
13 Correct 386 ms 31224 KB Output is correct
14 Correct 381 ms 30176 KB Output is correct
15 Correct 350 ms 29764 KB Output is correct
16 Correct 259 ms 27540 KB Output is correct
17 Correct 283 ms 27512 KB Output is correct
18 Correct 122 ms 21932 KB Output is correct
19 Correct 390 ms 31320 KB Output is correct
20 Correct 392 ms 30696 KB Output is correct
21 Correct 392 ms 31192 KB Output is correct
22 Correct 248 ms 26568 KB Output is correct
23 Correct 210 ms 26448 KB Output is correct
24 Correct 95 ms 21552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
3 Correct 6 ms 11980 KB Output is correct
4 Correct 5 ms 11980 KB Output is correct
5 Correct 6 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 17 ms 13272 KB Output is correct
8 Correct 17 ms 13268 KB Output is correct
9 Correct 17 ms 13260 KB Output is correct
10 Correct 13 ms 12876 KB Output is correct
11 Correct 14 ms 12876 KB Output is correct
12 Correct 9 ms 12492 KB Output is correct
13 Correct 15 ms 13152 KB Output is correct
14 Correct 15 ms 13100 KB Output is correct
15 Correct 16 ms 13100 KB Output is correct
16 Correct 13 ms 12628 KB Output is correct
17 Correct 13 ms 12844 KB Output is correct
18 Correct 10 ms 12420 KB Output is correct
19 Correct 349 ms 29744 KB Output is correct
20 Correct 352 ms 29676 KB Output is correct
21 Correct 341 ms 29744 KB Output is correct
22 Correct 219 ms 26992 KB Output is correct
23 Correct 255 ms 27052 KB Output is correct
24 Correct 117 ms 22024 KB Output is correct
25 Correct 348 ms 29488 KB Output is correct
26 Correct 329 ms 29476 KB Output is correct
27 Correct 331 ms 29204 KB Output is correct
28 Correct 242 ms 26472 KB Output is correct
29 Correct 207 ms 26416 KB Output is correct
30 Correct 96 ms 21608 KB Output is correct
31 Correct 386 ms 31224 KB Output is correct
32 Correct 381 ms 30176 KB Output is correct
33 Correct 350 ms 29764 KB Output is correct
34 Correct 259 ms 27540 KB Output is correct
35 Correct 283 ms 27512 KB Output is correct
36 Correct 122 ms 21932 KB Output is correct
37 Correct 390 ms 31320 KB Output is correct
38 Correct 392 ms 30696 KB Output is correct
39 Correct 392 ms 31192 KB Output is correct
40 Correct 248 ms 26568 KB Output is correct
41 Correct 210 ms 26448 KB Output is correct
42 Correct 95 ms 21552 KB Output is correct
43 Correct 791 ms 53964 KB Output is correct
44 Correct 777 ms 54064 KB Output is correct
45 Correct 751 ms 53804 KB Output is correct
46 Correct 401 ms 42408 KB Output is correct
47 Correct 482 ms 42400 KB Output is correct
48 Correct 124 ms 21812 KB Output is correct
49 Correct 759 ms 53716 KB Output is correct
50 Correct 872 ms 53720 KB Output is correct
51 Correct 746 ms 53596 KB Output is correct
52 Correct 418 ms 38056 KB Output is correct
53 Correct 266 ms 32560 KB Output is correct