Submission #844468

# Submission time Handle Problem Language Result Execution time Memory
844468 2023-09-05T13:21:37 Z mickey080929 None (JOI16_worst_reporter2) C++17
100 / 100
201 ms 32704 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9;
typedef pair<int,int> pii;

pii A[201010], B[201010];
vector<int> v[201010];

struct LazySegmentTree{
    int tree[401010 * 4];
    int lazy[401010 * 4];
    void init(int n) {
        fill(tree, tree+n*4+10, inf);
        fill(lazy, lazy+n*4+10, 0);
    }
    void propagate(int node, int s, int e) {
        if (!lazy[node]) return;
        tree[node] += lazy[node];
        if (s != e) {
            lazy[node<<1] += lazy[node];
            lazy[node<<1|1] += lazy[node];
        }
        lazy[node] = 0;
    }
    void update_point(int node, int s, int e, int tar, int val) {
        propagate(node, s, e);
        if (s > tar || tar > e) return;
        if (s == e) {
            tree[node] = val;
            return;
        }
        int mid = s + e >> 1;
        update_point(node<<1, s, mid, tar, val);
        update_point(node<<1|1, mid+1, e, tar, val);
        tree[node] = min(tree[node<<1], tree[node<<1|1]);
    }
    void update_range(int node, int s, int e, int l, int r, int val) {
        propagate(node, s, e);
        if (l > e || s > r) return;
        if (l <= s && e <= r) {
            lazy[node] = val;
            propagate(node, s, e);
            return;
        }
        int mid = s + e >> 1;
        update_range(node<<1, s, mid, l, r, val);
        update_range(node<<1|1, mid+1, e, l, r, val);
        tree[node] = min(tree[node<<1], tree[node<<1|1]);
    }
    int query(int node, int s, int e, int l, int r) {
        propagate(node, s, e);
        if (l > e || s > r) return inf;
        if (l <= s && e <= r) return tree[node];
        int mid = s + e >> 1;
        return min(query(node<<1, s, mid, l, r), query(node<<1|1, mid+1, e, l, r));
    }
} seg;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> t;
    for (int i=1; i<=n; i++) {
        scanf("%d %d", &A[i].first, &A[i].second);
        t.push_back(A[i].second);
    }
    for (int i=1; i<=n; i++) {
        scanf("%d %d", &B[i].first, &B[i].second);
        t.push_back(B[i].second);
    }
    reverse(A+1, A+n+1);
    reverse(B+1, B+n+1);
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    int m = (int) t.size();
    for (int i=1; i<=n; i++) {
        A[i].second = lower_bound(t.begin(), t.end(), A[i].second) - t.begin() + 1;
        B[i].second = lower_bound(t.begin(), t.end(), B[i].second) - t.begin() + 1;
    }
    seg.init(m);
    int j = 1, ans = 0;
    for (int i=1; i<=n; i++) {
        while (j <= n && A[j].second <= B[i].second) {
            v[A[j].first].push_back(A[j].second);
            j ++;
        }
        if (v[B[i].first].empty() || seg.query(1, 1, m, v[B[i].first].back(), m) <= 0) {
            seg.update_point(1, 1, m, B[i].second, j - i - 1);
            ans ++;
        }
        else {
            seg.update_range(1, 1, m, v[B[i].first].back(), m, -1);
            v[B[i].first].pop_back();
        }
    }
    printf("%d\n", ans);
}

Compilation message

worst_reporter2.cpp: In member function 'void LazySegmentTree::update_point(int, int, int, int, int)':
worst_reporter2.cpp:34:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |         int mid = s + e >> 1;
      |                   ~~^~~
worst_reporter2.cpp: In member function 'void LazySegmentTree::update_range(int, int, int, int, int, int)':
worst_reporter2.cpp:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int mid = s + e >> 1;
      |                   ~~^~~
worst_reporter2.cpp: In member function 'int LazySegmentTree::query(int, int, int, int, int)':
worst_reporter2.cpp:56:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         int mid = s + e >> 1;
      |                   ~~^~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
worst_reporter2.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d %d", &A[i].first, &A[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d %d", &B[i].first, &B[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8740 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8740 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8740 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 6 ms 11096 KB Output is correct
24 Correct 5 ms 11100 KB Output is correct
25 Correct 5 ms 11096 KB Output is correct
26 Correct 6 ms 11100 KB Output is correct
27 Correct 5 ms 11096 KB Output is correct
28 Correct 5 ms 10844 KB Output is correct
29 Correct 5 ms 10840 KB Output is correct
30 Correct 5 ms 11096 KB Output is correct
31 Correct 6 ms 10840 KB Output is correct
32 Correct 6 ms 10840 KB Output is correct
33 Correct 6 ms 10840 KB Output is correct
34 Correct 5 ms 10840 KB Output is correct
35 Correct 5 ms 10840 KB Output is correct
36 Correct 6 ms 10840 KB Output is correct
37 Correct 5 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8740 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 2 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 6 ms 11096 KB Output is correct
24 Correct 5 ms 11100 KB Output is correct
25 Correct 5 ms 11096 KB Output is correct
26 Correct 6 ms 11100 KB Output is correct
27 Correct 5 ms 11096 KB Output is correct
28 Correct 5 ms 10844 KB Output is correct
29 Correct 5 ms 10840 KB Output is correct
30 Correct 5 ms 11096 KB Output is correct
31 Correct 6 ms 10840 KB Output is correct
32 Correct 6 ms 10840 KB Output is correct
33 Correct 6 ms 10840 KB Output is correct
34 Correct 5 ms 10840 KB Output is correct
35 Correct 5 ms 10840 KB Output is correct
36 Correct 6 ms 10840 KB Output is correct
37 Correct 5 ms 10840 KB Output is correct
38 Correct 186 ms 32704 KB Output is correct
39 Correct 173 ms 31416 KB Output is correct
40 Correct 187 ms 31420 KB Output is correct
41 Correct 170 ms 31420 KB Output is correct
42 Correct 201 ms 31680 KB Output is correct
43 Correct 176 ms 26780 KB Output is correct
44 Correct 172 ms 27068 KB Output is correct
45 Correct 171 ms 27040 KB Output is correct
46 Correct 157 ms 27704 KB Output is correct
47 Correct 176 ms 28752 KB Output is correct
48 Correct 170 ms 26540 KB Output is correct
49 Correct 181 ms 26180 KB Output is correct
50 Correct 172 ms 26300 KB Output is correct
51 Correct 154 ms 27140 KB Output is correct
52 Correct 165 ms 27072 KB Output is correct