답안 #471333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471333 2021-09-08T12:57:40 Z spike1236 Examination (JOI19_examination) C++14
100 / 100
1771 ms 62484 KB
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
///#pragma GCC optimize("O3")
///#pragma GCC target("avx,avx2,fma")
using namespace std;
#define f first
#define s second

const int MAXN = 2e5 + 10;
pair <int, int> a[MAXN];
map <int, vector <vector <int> > > q;
vector <int> fw[MAXN], comp, comp2[MAXN];
int ans[MAXN];

int get_a(int v) {
    return lower_bound(comp.begin(), comp.end(), v) - comp.begin() + 1;
}

int get_b(int x, int y) {
    return lower_bound(comp2[x].begin(), comp2[x].end(), y) - comp2[x].begin() + 1;
}

void pre_upd(int x, int y) {
    for(int i = get_a(x); i <= comp.size(); i += i & -i) comp2[i].push_back(y);
}

void pre_get(int x, int y) {
    for(int i = get_a(x); i > 0; i -= i & -i) comp2[i].push_back(y);
}

void upd(int x, int y, int val) {
    for(int i = get_a(x); i <= comp.size(); i += i & -i)
        for(int j = get_b(i, y); j <= comp2[i].size(); j += j & -j)
            fw[i][j] += val;
}

int get(int x, int y) {
    int res = 0;
    for(int i = get_a(x); i > 0; i -= i & -i) {
        for(int j = get_b(i, y); j > 0; j -= j & -j) {
            res += fw[i][j];
        }
    }
    return res;
}

bool cmp(const pair <int, int> &x, const pair <int, int> &y) {
    return (x.f + x.s < y.f + y.s);
}

int main() {
    int n, qq;
    cin >> n >> qq;
    for(int i = 0; i < n; ++i) {
        cin >> a[i].f >> a[i].s;
        comp.push_back(a[i].f);
    }
    sort(a, a + n, &cmp);
    int x, y, z;
    for(int i = 0; i < qq; ++i) {
        cin >> x >> y >> z;
        q[z].push_back({x, y, i});
        comp.push_back(x - 1);
    }
    comp.push_back(1e9);
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for(int i = 0; i < n; ++i) pre_upd(a[i].f, a[i].s);
    for(auto &it : q) {
        for(auto &j : it.s) {
            pre_get(j[0] - 1, j[1] - 1);
            pre_get(j[0] - 1, 1e9);
            pre_get(1e9, j[1] - 1);
        }
    }
    for(int i = 1; i <= comp.size(); ++i) {
        sort(comp2[i].begin(), comp2[i].end());
        comp2[i].erase(unique(comp2[i].begin(), comp2[i].end()), comp2[i].end());
        fw[i].resize(comp2[i].size() + 1);
    }
    for(int i = 0; i < n; ++i) upd(a[i].f, a[i].s, 1);
    int ptr = 0;
    for(auto it : q) {
        while(ptr < n && a[ptr].f + a[ptr].s < it.f) {
            upd(a[ptr].f, a[ptr].s, -1);
            ++ptr;
        }
        for(auto j : q[it.f]) {
            ans[j[2]] = n - ptr - get(j[0] - 1, 1e9) - get(1e9, j[1] - 1) + get(j[0] - 1, j[1] - 1);
        }
    }
    for(int i = 0; i < qq; ++i) cout << ans[i] << '\n';
    return 0;
}

Compilation message

examination.cpp: In function 'void pre_upd(int, int)':
examination.cpp:27:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = get_a(x); i <= comp.size(); i += i & -i) comp2[i].push_back(y);
      |                           ~~^~~~~~~~~~~~~~
examination.cpp: In function 'void upd(int, int, int)':
examination.cpp:35:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = get_a(x); i <= comp.size(); i += i & -i)
      |                           ~~^~~~~~~~~~~~~~
examination.cpp:36:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j = get_b(i, y); j <= comp2[i].size(); j += j & -j)
      |                                  ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 1; i <= comp.size(); ++i) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 7 ms 9704 KB Output is correct
4 Correct 5 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 34 ms 11064 KB Output is correct
8 Correct 31 ms 11016 KB Output is correct
9 Correct 34 ms 11088 KB Output is correct
10 Correct 22 ms 10828 KB Output is correct
11 Correct 19 ms 10420 KB Output is correct
12 Correct 12 ms 10172 KB Output is correct
13 Correct 27 ms 10992 KB Output is correct
14 Correct 32 ms 10960 KB Output is correct
15 Correct 26 ms 10980 KB Output is correct
16 Correct 19 ms 10128 KB Output is correct
17 Correct 24 ms 10828 KB Output is correct
18 Correct 10 ms 10048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1185 ms 50268 KB Output is correct
2 Correct 1130 ms 48948 KB Output is correct
3 Correct 1292 ms 51064 KB Output is correct
4 Correct 566 ms 41416 KB Output is correct
5 Correct 390 ms 28096 KB Output is correct
6 Correct 220 ms 26336 KB Output is correct
7 Correct 811 ms 44796 KB Output is correct
8 Correct 1027 ms 47184 KB Output is correct
9 Correct 853 ms 45500 KB Output is correct
10 Correct 279 ms 25356 KB Output is correct
11 Correct 459 ms 41768 KB Output is correct
12 Correct 218 ms 25324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1185 ms 50268 KB Output is correct
2 Correct 1130 ms 48948 KB Output is correct
3 Correct 1292 ms 51064 KB Output is correct
4 Correct 566 ms 41416 KB Output is correct
5 Correct 390 ms 28096 KB Output is correct
6 Correct 220 ms 26336 KB Output is correct
7 Correct 811 ms 44796 KB Output is correct
8 Correct 1027 ms 47184 KB Output is correct
9 Correct 853 ms 45500 KB Output is correct
10 Correct 279 ms 25356 KB Output is correct
11 Correct 459 ms 41768 KB Output is correct
12 Correct 218 ms 25324 KB Output is correct
13 Correct 1517 ms 50100 KB Output is correct
14 Correct 1357 ms 49180 KB Output is correct
15 Correct 1042 ms 47480 KB Output is correct
16 Correct 687 ms 42736 KB Output is correct
17 Correct 521 ms 29108 KB Output is correct
18 Correct 218 ms 23476 KB Output is correct
19 Correct 1487 ms 51548 KB Output is correct
20 Correct 1430 ms 50556 KB Output is correct
21 Correct 1479 ms 51432 KB Output is correct
22 Correct 273 ms 25260 KB Output is correct
23 Correct 463 ms 42264 KB Output is correct
24 Correct 169 ms 25264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 7 ms 9704 KB Output is correct
4 Correct 5 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 34 ms 11064 KB Output is correct
8 Correct 31 ms 11016 KB Output is correct
9 Correct 34 ms 11088 KB Output is correct
10 Correct 22 ms 10828 KB Output is correct
11 Correct 19 ms 10420 KB Output is correct
12 Correct 12 ms 10172 KB Output is correct
13 Correct 27 ms 10992 KB Output is correct
14 Correct 32 ms 10960 KB Output is correct
15 Correct 26 ms 10980 KB Output is correct
16 Correct 19 ms 10128 KB Output is correct
17 Correct 24 ms 10828 KB Output is correct
18 Correct 10 ms 10048 KB Output is correct
19 Correct 1185 ms 50268 KB Output is correct
20 Correct 1130 ms 48948 KB Output is correct
21 Correct 1292 ms 51064 KB Output is correct
22 Correct 566 ms 41416 KB Output is correct
23 Correct 390 ms 28096 KB Output is correct
24 Correct 220 ms 26336 KB Output is correct
25 Correct 811 ms 44796 KB Output is correct
26 Correct 1027 ms 47184 KB Output is correct
27 Correct 853 ms 45500 KB Output is correct
28 Correct 279 ms 25356 KB Output is correct
29 Correct 459 ms 41768 KB Output is correct
30 Correct 218 ms 25324 KB Output is correct
31 Correct 1517 ms 50100 KB Output is correct
32 Correct 1357 ms 49180 KB Output is correct
33 Correct 1042 ms 47480 KB Output is correct
34 Correct 687 ms 42736 KB Output is correct
35 Correct 521 ms 29108 KB Output is correct
36 Correct 218 ms 23476 KB Output is correct
37 Correct 1487 ms 51548 KB Output is correct
38 Correct 1430 ms 50556 KB Output is correct
39 Correct 1479 ms 51432 KB Output is correct
40 Correct 273 ms 25260 KB Output is correct
41 Correct 463 ms 42264 KB Output is correct
42 Correct 169 ms 25264 KB Output is correct
43 Correct 1721 ms 61752 KB Output is correct
44 Correct 1771 ms 62484 KB Output is correct
45 Correct 1741 ms 62464 KB Output is correct
46 Correct 827 ms 53548 KB Output is correct
47 Correct 577 ms 32968 KB Output is correct
48 Correct 228 ms 22584 KB Output is correct
49 Correct 1503 ms 60268 KB Output is correct
50 Correct 1702 ms 61576 KB Output is correct
51 Correct 1438 ms 57836 KB Output is correct
52 Correct 449 ms 29744 KB Output is correct
53 Correct 539 ms 49128 KB Output is correct