Submission #288181

# Submission time Handle Problem Language Result Execution time Memory
288181 2020-09-01T09:37:30 Z Alexa2001 None (JOI16_worst_reporter2) C++17
100 / 100
285 ms 22636 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2e5 + 5;

vector<int> last[Nmax];
int n;
int score1[Nmax], score2[Nmax], id1[Nmax], id2[Nmax];

#define left_son (node<<1)
#define right_son ((node<<1)|1)
#define mid ((st+dr)>>1)

class SegTree
{
    int a[Nmax<<2], lazy[Nmax<<2];

    void propag(int node)
    {
        if(!lazy[node]) return;
        lazy[left_son] += lazy[node];
        lazy[right_son] += lazy[node];
        a[left_son] += lazy[node];
        a[right_son] += lazy[node];
        lazy[node] = 0;
    }

public:
    void update(int node, int st, int dr, int L, int R, int add)
    {
        if(L <= st && dr <= R)
        {
            lazy[node] += add;
            a[node] += add;
            return;
        }

        propag(node);

        if(L <= mid) update(left_son, st, mid, L, R, add);
        if(mid < R) update(right_son, mid+1, dr, L, R, add);

        a[node] = min(a[left_son], a[right_son]);
    }

    bool good()
    {
        return a[1] >= 0;
    }
} aint;

int solve()
{
    int i, j = 0;
    int matches = 0;

    for(i=1; i<=n; ++i)
    {
        while(j<n && score1[i] <= score2[j+1])
        {
            ++j;
            aint.update(1, 1, n, j, n, +1);
            last[id2[j]].push_back(j);
        }

        if(last[id1[i]].empty())
        {
            aint.update(1, 1, n, j, n, -1);
            continue;
        }

        int pos = last[id1[i]].back();

        aint.update(1, 1, n, pos, n, -1);

        if(aint.good())
        {
            ++matches;
            last[id1[i]].pop_back();
        }
        else
        {
            aint.update(1, 1, n, pos, n, +1);
            aint.update(1, 1, n, j, n, -1);
        }
    }

    return matches;
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.tie(0); cin.sync_with_stdio(false);

    cin >> n;

    int i;
    for(i=1; i<=n; ++i) cin >> id1[i] >> score1[i];
    for(i=1; i<=n; ++i) cin >> id2[i] >> score2[i];

    cout << n - solve() << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 3 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 3 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 3 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 3 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 8 ms 5504 KB Output is correct
24 Correct 8 ms 5504 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 8 ms 5504 KB Output is correct
27 Correct 8 ms 5632 KB Output is correct
28 Correct 7 ms 5376 KB Output is correct
29 Correct 7 ms 5376 KB Output is correct
30 Correct 7 ms 5376 KB Output is correct
31 Correct 8 ms 5376 KB Output is correct
32 Correct 7 ms 5376 KB Output is correct
33 Correct 6 ms 5376 KB Output is correct
34 Correct 7 ms 5376 KB Output is correct
35 Correct 6 ms 5376 KB Output is correct
36 Correct 7 ms 5376 KB Output is correct
37 Correct 6 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 3 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 3 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 3 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 8 ms 5504 KB Output is correct
24 Correct 8 ms 5504 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 8 ms 5504 KB Output is correct
27 Correct 8 ms 5632 KB Output is correct
28 Correct 7 ms 5376 KB Output is correct
29 Correct 7 ms 5376 KB Output is correct
30 Correct 7 ms 5376 KB Output is correct
31 Correct 8 ms 5376 KB Output is correct
32 Correct 7 ms 5376 KB Output is correct
33 Correct 6 ms 5376 KB Output is correct
34 Correct 7 ms 5376 KB Output is correct
35 Correct 6 ms 5376 KB Output is correct
36 Correct 7 ms 5376 KB Output is correct
37 Correct 6 ms 5376 KB Output is correct
38 Correct 285 ms 22636 KB Output is correct
39 Correct 276 ms 21496 KB Output is correct
40 Correct 276 ms 21624 KB Output is correct
41 Correct 274 ms 21432 KB Output is correct
42 Correct 254 ms 21476 KB Output is correct
43 Correct 196 ms 16868 KB Output is correct
44 Correct 202 ms 17016 KB Output is correct
45 Correct 201 ms 17016 KB Output is correct
46 Correct 253 ms 17528 KB Output is correct
47 Correct 188 ms 18680 KB Output is correct
48 Correct 179 ms 16376 KB Output is correct
49 Correct 165 ms 16248 KB Output is correct
50 Correct 186 ms 16376 KB Output is correct
51 Correct 242 ms 17016 KB Output is correct
52 Correct 164 ms 17016 KB Output is correct