답안 #355472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
355472 2021-01-22T14:19:46 Z parsabahrami Examination (JOI19_examination) C++17
43 / 100
599 ms 46048 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e5 + 10;
vector<int> vec[N], F[N], comp = {(int) -1e9};
pii A[N]; int n, q, R[N], id[N], X[N], Y[N], Z[N];

void init(int x, int y) {
    for (; x < N; x += x & -x) {
        vec[x].push_back(y);
    }
}

void upd(int r, int _c) {
    for (; r < N; r += r & -r) {
        int c = lower_bound(vec[r].begin(), vec[r].end(), _c) - vec[r].begin();
        for (; c < SZ(F[r]); c += c & -c) F[r][c]++;
    }
}

int get(int r, int _c) {
    int ret = 0;
    for (; r; r -= r & -r) {
        int c = upper_bound(vec[r].begin(), vec[r].end(), _c) - vec[r].begin() - 1;
        for (; c; c -= c & -c) ret += F[r][c];
    }
    return ret;
}

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].F, &A[i].S), comp.push_back(-A[i].F);
    sort(A + 1, A + n + 1, [&] (pii a, pii b) { return a.F + a.S > b.F + b.S; });
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &X[i], &Y[i], &Z[i]); id[i] = i;
        comp.push_back(-X[i]);
    }
    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
    sort(id + 1, id + q + 1, [&] (int i, int j) { return Z[i] > Z[j]; });
    for (int i = 1; i <= n; i++) {
        init(lower_bound(comp.begin(), comp.end(), -A[i].F) - comp.begin(), -A[i].S);
    }
    for (int i = 0; i < N; i++) {
        vec[i].push_back(-1e9); vec[i].push_back(0);
        sort(vec[i].begin(), vec[i].end());
        vec[i].resize(unique(vec[i].begin(), vec[i].end()) - vec[i].begin());
        while (SZ(F[i]) < SZ(vec[i]) + 5) F[i].push_back(0);
    }
    int ptr = 1;
    for (int _ = 1; _ <= q; _++) {
        int i = id[_];
        while (ptr <= n && A[ptr].F + A[ptr].S >= Z[i]) {
            upd(lower_bound(comp.begin(), comp.end(), -A[ptr].F) - comp.begin(), -A[ptr].S);
            ptr++;
        }
        R[i] = get(lower_bound(comp.begin(), comp.end(), -X[i]) - comp.begin(), -Y[i]);
    }
    for (int i = 1; i <= q; i++) printf("%d\n", R[i]);
    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:41:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |     for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].F, &A[i].S), comp.push_back(-A[i].F);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         scanf("%d%d%d", &X[i], &Y[i], &Z[i]); id[i] = i;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 12908 KB Output is correct
2 Correct 35 ms 12908 KB Output is correct
3 Correct 34 ms 12928 KB Output is correct
4 Correct 35 ms 12908 KB Output is correct
5 Correct 34 ms 12908 KB Output is correct
6 Correct 34 ms 12908 KB Output is correct
7 Correct 45 ms 13548 KB Output is correct
8 Correct 48 ms 13548 KB Output is correct
9 Correct 46 ms 13548 KB Output is correct
10 Correct 41 ms 13292 KB Output is correct
11 Correct 44 ms 13644 KB Output is correct
12 Correct 41 ms 13292 KB Output is correct
13 Correct 44 ms 13420 KB Output is correct
14 Correct 45 ms 13548 KB Output is correct
15 Correct 46 ms 13548 KB Output is correct
16 Correct 42 ms 13548 KB Output is correct
17 Correct 42 ms 13292 KB Output is correct
18 Correct 39 ms 13292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 551 ms 29152 KB Output is correct
2 Correct 542 ms 29188 KB Output is correct
3 Correct 528 ms 29036 KB Output is correct
4 Correct 268 ms 24800 KB Output is correct
5 Correct 313 ms 30336 KB Output is correct
6 Correct 192 ms 25332 KB Output is correct
7 Correct 470 ms 28000 KB Output is correct
8 Correct 498 ms 29024 KB Output is correct
9 Correct 456 ms 27872 KB Output is correct
10 Correct 289 ms 29792 KB Output is correct
11 Correct 215 ms 22880 KB Output is correct
12 Correct 145 ms 24416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 551 ms 29152 KB Output is correct
2 Correct 542 ms 29188 KB Output is correct
3 Correct 528 ms 29036 KB Output is correct
4 Correct 268 ms 24800 KB Output is correct
5 Correct 313 ms 30336 KB Output is correct
6 Correct 192 ms 25332 KB Output is correct
7 Correct 470 ms 28000 KB Output is correct
8 Correct 498 ms 29024 KB Output is correct
9 Correct 456 ms 27872 KB Output is correct
10 Correct 289 ms 29792 KB Output is correct
11 Correct 215 ms 22880 KB Output is correct
12 Correct 145 ms 24416 KB Output is correct
13 Correct 593 ms 29424 KB Output is correct
14 Correct 583 ms 29428 KB Output is correct
15 Correct 552 ms 29060 KB Output is correct
16 Correct 316 ms 25056 KB Output is correct
17 Correct 350 ms 30816 KB Output is correct
18 Correct 187 ms 25184 KB Output is correct
19 Correct 599 ms 29408 KB Output is correct
20 Correct 595 ms 29664 KB Output is correct
21 Correct 556 ms 29024 KB Output is correct
22 Correct 287 ms 29824 KB Output is correct
23 Correct 225 ms 23008 KB Output is correct
24 Correct 142 ms 24416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 12908 KB Output is correct
2 Correct 35 ms 12908 KB Output is correct
3 Correct 34 ms 12928 KB Output is correct
4 Correct 35 ms 12908 KB Output is correct
5 Correct 34 ms 12908 KB Output is correct
6 Correct 34 ms 12908 KB Output is correct
7 Correct 45 ms 13548 KB Output is correct
8 Correct 48 ms 13548 KB Output is correct
9 Correct 46 ms 13548 KB Output is correct
10 Correct 41 ms 13292 KB Output is correct
11 Correct 44 ms 13644 KB Output is correct
12 Correct 41 ms 13292 KB Output is correct
13 Correct 44 ms 13420 KB Output is correct
14 Correct 45 ms 13548 KB Output is correct
15 Correct 46 ms 13548 KB Output is correct
16 Correct 42 ms 13548 KB Output is correct
17 Correct 42 ms 13292 KB Output is correct
18 Correct 39 ms 13292 KB Output is correct
19 Correct 551 ms 29152 KB Output is correct
20 Correct 542 ms 29188 KB Output is correct
21 Correct 528 ms 29036 KB Output is correct
22 Correct 268 ms 24800 KB Output is correct
23 Correct 313 ms 30336 KB Output is correct
24 Correct 192 ms 25332 KB Output is correct
25 Correct 470 ms 28000 KB Output is correct
26 Correct 498 ms 29024 KB Output is correct
27 Correct 456 ms 27872 KB Output is correct
28 Correct 289 ms 29792 KB Output is correct
29 Correct 215 ms 22880 KB Output is correct
30 Correct 145 ms 24416 KB Output is correct
31 Correct 593 ms 29424 KB Output is correct
32 Correct 583 ms 29428 KB Output is correct
33 Correct 552 ms 29060 KB Output is correct
34 Correct 316 ms 25056 KB Output is correct
35 Correct 350 ms 30816 KB Output is correct
36 Correct 187 ms 25184 KB Output is correct
37 Correct 599 ms 29408 KB Output is correct
38 Correct 595 ms 29664 KB Output is correct
39 Correct 556 ms 29024 KB Output is correct
40 Correct 287 ms 29824 KB Output is correct
41 Correct 225 ms 23008 KB Output is correct
42 Correct 142 ms 24416 KB Output is correct
43 Runtime error 224 ms 46048 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -