답안 #255095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255095 2020-07-31T09:13:53 Z arujbansal Examination (JOI19_examination) C++17
2 / 100
3000 ms 27896 KB
#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define trav(e, x) for (auto &e : x)
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i+1
#define rc(i) 2*i+2
#define int long long
using namespace std;
typedef pair<int, int> ii;

struct pupil {
    pair<int, int> math, info, total;
    int dep;
};

bool comp(pupil x, pupil y) {
    if (x.info.first != y.info.first) return x.info.first < y.info.first;
    if (x.math.first != y.math.first) return x.math.first < y.math.first;
    return x.total.first < y.total.first;
}

struct SegmentTree {
    int n;
    vector<pupil> tree;


    void init(int x) {
        n = x;
        tree.resize(4 * n);
    }

    static pupil merge(pupil x, pupil y) {
        pupil ans;
        ans.math.first = min(x.math.first, y.math.first);
        ans.math.second = max(x.math.second, y.math.second);

        ans.info.first = min(x.info.first, y.info.first);
        ans.info.second = max(x.info.second, y.info.second);

        ans.total.first = min(x.total.first, y.total.first);
        ans.total.second = max(x.total.second, y.total.second);

        ans.dep = x.dep + y.dep;

        return ans;
    }

    void build(int i, int l, int r, vector<pupil> &a) {
        if (l == r) tree[i] = a[l];
        else {
            int mid = (l + r) / 2;
            build(lc(i), l, mid, a);
            build(rc(i), mid + 1, r, a);
            tree[i] = merge(tree[lc(i)], tree[rc(i)]);
        }
    }

    int query(int i, int l, int r, int math, int info, int total) {
        //cout << i << "\n";
        if (tree[i].math.second < math || tree[i].info.second < info || tree[i].total.second < total) return 0;
        if (tree[i].math.first >= math && tree[i].info.first >= info && tree[i].total.first >= total)
            return tree[i].dep;
        int mid = (l + r) / 2;
        return query(lc(i), l, mid, math, info, total) + query(rc(i), mid + 1, r, math, info, total);

    }

    void build(vector<pupil> &a) { build(0, 0, n - 1, a); }

    int query(int math, int info, int total) { return query(0, 0, n - 1, math, info, total); }
};


signed main() {
    FAST_IO;
    //FILE_IO;

    int n, q;
    cin >> n >> q;
    vector<pupil> students(n);
    for (int i = 0; i < n; i++) {
        cin >> students[i].math.first >> students[i].info.first;
        students[i].math.second = students[i].math.first;
        students[i].info.second = students[i].info.first;
        students[i].total.first = students[i].total.second = students[i].math.first + students[i].info.first;
        students[i].dep = 1;
    }
    //sort(all(students), comp);
    SegmentTree tree;
    tree.init(n);
    tree.build(students);
    //cout << tree.tree[0].math.second << " " << tree.tree[0].info.second << " " << tree.tree[0].total.second << " ";
    while (q--) {
        int x, y, z;
        cin >> x >> y >> z;
        cout << tree.query(x, y, z) << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 73 ms 1152 KB Output is correct
8 Correct 74 ms 1236 KB Output is correct
9 Correct 77 ms 1152 KB Output is correct
10 Correct 88 ms 1152 KB Output is correct
11 Correct 87 ms 1152 KB Output is correct
12 Correct 83 ms 1152 KB Output is correct
13 Correct 82 ms 1152 KB Output is correct
14 Correct 86 ms 1152 KB Output is correct
15 Correct 86 ms 1152 KB Output is correct
16 Correct 32 ms 1152 KB Output is correct
17 Correct 42 ms 1228 KB Output is correct
18 Correct 2 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3054 ms 27896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3054 ms 27896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 73 ms 1152 KB Output is correct
8 Correct 74 ms 1236 KB Output is correct
9 Correct 77 ms 1152 KB Output is correct
10 Correct 88 ms 1152 KB Output is correct
11 Correct 87 ms 1152 KB Output is correct
12 Correct 83 ms 1152 KB Output is correct
13 Correct 82 ms 1152 KB Output is correct
14 Correct 86 ms 1152 KB Output is correct
15 Correct 86 ms 1152 KB Output is correct
16 Correct 32 ms 1152 KB Output is correct
17 Correct 42 ms 1228 KB Output is correct
18 Correct 2 ms 1152 KB Output is correct
19 Execution timed out 3054 ms 27896 KB Time limit exceeded
20 Halted 0 ms 0 KB -