Submission #341013

# Submission time Handle Problem Language Result Execution time Memory
341013 2020-12-28T22:02:57 Z ijxjdjd Examination (JOI19_examination) C++14
100 / 100
1878 ms 12944 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int MAXN = (int)(1e5)+5;

struct query {
    int X;
    int Y;
    int Z;
    int i;
};
vector<query> vec;
vector<int> byB;
unordered_map<int, int> cnt;
int ans[MAXN];
const int K = 330;
int arr[MAXN];
vector<int> keep[MAXN];
int main() {
//    string s = "input.in";
//    freopen(s.c_str(), "r", stdin);
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        arr[i] = -1;
        int A, B;
        cin >> A >> B;
        vec.push_back({A, B, -1, -1});
        byB.push_back(B);
    }
    sort(byB.begin(), byB.end());
    int c = 1;
    for (int i = 1; i < N; i++) {
        if (byB[i] != byB[i-1]) {
            cnt[byB[i-1]] = c;
        }
        c++;
    }
    cnt[byB[N-1]] = c;
    for (int i = 0; i < Q; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        vec.push_back({X, Y, Z, i});
    }
    sort(vec.begin(), vec.end(), [](const query& lhs, const query& rhs) {
         if (lhs.X != rhs.X) return lhs.X > rhs.X;
        if (lhs.Y != rhs.Y) return lhs.Y > rhs.Y;
        return lhs.i < rhs.i;})
        ;
    for (query q : vec) {
        if (q.i != -1) {
            int low = 0;
            int high = N-1;
            while (low < high) {
                int mid = (low + high)/2;
                if (byB[mid] >= q.Y) {
                    high = mid;
                }
                else {
                    low = mid+1;
                }
            }
            if (byB[high] >= q.Y) {
                for (int i = N-1; i >= high;) {
                    if ((i/K)*K >= high) {
                        if (keep[i/K].size() > 0) {
                            int l = 0;
                            int h = keep[i/K].size()-1;
                            while (l < h) {
                                int mid = (l + h)/2;
                                if (keep[i/K][mid] >= q.Z) {
                                    h = mid;
                                }
                                else {
                                    l = mid+1;
                                }
                            }
                            if (keep[i/K][h] >= q.Z) {
                                ans[q.i] += keep[i/K].size() - h;
                            }
                        }

                        i = (i/K)*K - 1;
                    }
                    else {
                        if (arr[i] >= q.Z) {
                            ans[q.i]++;
                        }
                        i--;
                    }
                }
            }
        }
        else {
            cnt[q.Y]--;
            int a = cnt[q.Y];
            arr[a] = q.X + q.Y;
            keep[a/K].push_back(q.X + q.Y);
            sort(keep[a/K].begin(), keep[a/K].end());
        }
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 27 ms 3180 KB Output is correct
8 Correct 27 ms 3180 KB Output is correct
9 Correct 26 ms 3052 KB Output is correct
10 Correct 25 ms 2924 KB Output is correct
11 Correct 20 ms 3052 KB Output is correct
12 Correct 17 ms 2924 KB Output is correct
13 Correct 26 ms 3052 KB Output is correct
14 Correct 26 ms 3052 KB Output is correct
15 Correct 26 ms 3072 KB Output is correct
16 Correct 24 ms 3052 KB Output is correct
17 Correct 23 ms 2984 KB Output is correct
18 Correct 8 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1008 ms 11440 KB Output is correct
2 Correct 1012 ms 11640 KB Output is correct
3 Correct 1012 ms 11732 KB Output is correct
4 Correct 891 ms 8676 KB Output is correct
5 Correct 805 ms 11728 KB Output is correct
6 Correct 439 ms 8612 KB Output is correct
7 Correct 980 ms 11636 KB Output is correct
8 Correct 1175 ms 11732 KB Output is correct
9 Correct 1159 ms 11732 KB Output is correct
10 Correct 890 ms 11476 KB Output is correct
11 Correct 840 ms 8412 KB Output is correct
12 Correct 271 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1008 ms 11440 KB Output is correct
2 Correct 1012 ms 11640 KB Output is correct
3 Correct 1012 ms 11732 KB Output is correct
4 Correct 891 ms 8676 KB Output is correct
5 Correct 805 ms 11728 KB Output is correct
6 Correct 439 ms 8612 KB Output is correct
7 Correct 980 ms 11636 KB Output is correct
8 Correct 1175 ms 11732 KB Output is correct
9 Correct 1159 ms 11732 KB Output is correct
10 Correct 890 ms 11476 KB Output is correct
11 Correct 840 ms 8412 KB Output is correct
12 Correct 271 ms 8412 KB Output is correct
13 Correct 1221 ms 11732 KB Output is correct
14 Correct 1083 ms 11732 KB Output is correct
15 Correct 1010 ms 11732 KB Output is correct
16 Correct 959 ms 8704 KB Output is correct
17 Correct 853 ms 11948 KB Output is correct
18 Correct 432 ms 8532 KB Output is correct
19 Correct 1212 ms 11748 KB Output is correct
20 Correct 1180 ms 11620 KB Output is correct
21 Correct 1576 ms 11620 KB Output is correct
22 Correct 904 ms 11544 KB Output is correct
23 Correct 849 ms 8412 KB Output is correct
24 Correct 269 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 27 ms 3180 KB Output is correct
8 Correct 27 ms 3180 KB Output is correct
9 Correct 26 ms 3052 KB Output is correct
10 Correct 25 ms 2924 KB Output is correct
11 Correct 20 ms 3052 KB Output is correct
12 Correct 17 ms 2924 KB Output is correct
13 Correct 26 ms 3052 KB Output is correct
14 Correct 26 ms 3052 KB Output is correct
15 Correct 26 ms 3072 KB Output is correct
16 Correct 24 ms 3052 KB Output is correct
17 Correct 23 ms 2984 KB Output is correct
18 Correct 8 ms 2924 KB Output is correct
19 Correct 1008 ms 11440 KB Output is correct
20 Correct 1012 ms 11640 KB Output is correct
21 Correct 1012 ms 11732 KB Output is correct
22 Correct 891 ms 8676 KB Output is correct
23 Correct 805 ms 11728 KB Output is correct
24 Correct 439 ms 8612 KB Output is correct
25 Correct 980 ms 11636 KB Output is correct
26 Correct 1175 ms 11732 KB Output is correct
27 Correct 1159 ms 11732 KB Output is correct
28 Correct 890 ms 11476 KB Output is correct
29 Correct 840 ms 8412 KB Output is correct
30 Correct 271 ms 8412 KB Output is correct
31 Correct 1221 ms 11732 KB Output is correct
32 Correct 1083 ms 11732 KB Output is correct
33 Correct 1010 ms 11732 KB Output is correct
34 Correct 959 ms 8704 KB Output is correct
35 Correct 853 ms 11948 KB Output is correct
36 Correct 432 ms 8532 KB Output is correct
37 Correct 1212 ms 11748 KB Output is correct
38 Correct 1180 ms 11620 KB Output is correct
39 Correct 1576 ms 11620 KB Output is correct
40 Correct 904 ms 11544 KB Output is correct
41 Correct 849 ms 8412 KB Output is correct
42 Correct 269 ms 8412 KB Output is correct
43 Correct 1287 ms 12776 KB Output is correct
44 Correct 1293 ms 12884 KB Output is correct
45 Correct 1164 ms 12944 KB Output is correct
46 Correct 995 ms 8540 KB Output is correct
47 Correct 911 ms 12756 KB Output is correct
48 Correct 498 ms 8412 KB Output is correct
49 Correct 1270 ms 12884 KB Output is correct
50 Correct 1637 ms 12756 KB Output is correct
51 Correct 1878 ms 12884 KB Output is correct
52 Correct 979 ms 12452 KB Output is correct
53 Correct 859 ms 8412 KB Output is correct