Submission #839407

# Submission time Handle Problem Language Result Execution time Memory
839407 2023-08-30T01:59:24 Z anhduc2701 Examination (JOI19_examination) C++17
0 / 100
427 ms 51172 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n, q;
vector<pair<pair<int, int>, int>> s;

vector<int> poi;
vector<int> poi1;
struct BIT2D
{
    vector<int> po[maxn];
    vector<int> bit[maxn];
    void pre_upd(int x, int y)
    {
        for (int i = x; i >= 1; i -= i & (-i))
        {
            po[i].pb(y);
        }
    }
    void pre_get(int x, int y)
    {
        for (int i = x; i <= (int)(poi.size()); i += i & (-i))
        {
            po[i].pb(y);
        }
    }
    void init()
    {
        for (int i = 1; i <= (int)(poi.size()); i++)
        {
            sort(po[i].begin(), po[i].end());
            po[i].resize(unique(po[i].begin(), po[i].end()) - po[i].begin());
            bit[i].resize(po[i].size() + 1, 0);
        }
    }
    void upd(int x, int y)
    {
        for (int i = x; i >= 1; i -= i & (-i))
        {
            int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1;
            for (int j = id; j >= 1; j -= j & (-j))
            {
                bit[i][j] += 1;
            }
        }
    }
    int calc(int x, int y)
    {
        int res = 0;
        for (int i = x; i <= (int)(poi.size()); i += i & (-i))
        {
            int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1;
            for (int j = id; j < (int)(bit[i].size()); j += j & (-j))
            {
                res += bit[i][j];
            }
        }
        return res;
    }
} DS;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
    if (a.fi.fi == b.fi.fi)
        return a.se < b.se;
    return a.fi.fi < b.fi.fi;
}
int X[maxn];
int Y[maxn];
int A[maxn], B[maxn], C[maxn];
int ans[maxn];
signed main()
{
    // freopen("input.inp", "r", stdin);
    // freopen("output.out", "w", stdout);
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        poi.pb(y);
        poi1.pb(x + y);
        X[i] = x;
        Y[i] = y;
        s.pb({{x, i}, 0});
    }
    for (int i = 1; i <= q; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        A[i] = a;
        B[i] = b;
        C[i] = c;
        poi.pb(b);
        poi1.pb(c);
        s.pb({{a, i}, 1});
    }
    sort(poi.begin(), poi.end());
    sort(poi1.begin(), poi1.end());
    poi.resize(unique(poi.begin(), poi.end()) - poi.begin());
    poi1.resize(unique(poi1.begin(), poi1.end()) - poi1.begin());
    for (int i = 1; i <= n; i++)
    {
        int d = X[i] + Y[i];
        int c = lower_bound(poi.begin(), poi.end(), Y[i]) - poi.begin() + 1;
        d = lower_bound(poi1.begin(), poi1.end(), d) - poi1.begin() + 1;
        DS.pre_upd(c, d);
    }
    for (int i = 1; i <= q; i++)
    {
        int b = lower_bound(poi.begin(), poi.end(), B[i]) - poi.begin() + 1;
        int c = lower_bound(poi1.begin(), poi1.end(), C[i]) - poi1.begin() + 1;
        DS.pre_get(b, c);
    }
    sort(s.begin(), s.end());
    DS.init();

    for (int i = (int)(s.size()) - 1; i >= 0; i--)
    {
        int id = s[i].fi.se;
        int type = s[i].se;
        if (type == 0)
        {
            int d = X[id] + Y[id];
            int c = lower_bound(poi.begin(), poi.end(), Y[id]) - poi.begin() + 1;
            d = lower_bound(poi1.begin(), poi1.end(), d) - poi1.begin() + 1;
            // cout << s[i].fi.fi << ' ' << c << ' ' << d << ' ' << type << ' ' << id << '\n';
            DS.upd(c, d);
        }
        else
        {
            int b = lower_bound(poi.begin(), poi.end(), B[id]) - poi.begin() + 1;
            int c = lower_bound(poi1.begin(), poi1.end(), C[id]) - poi1.begin() + 1;
            // cout << s[i].fi.fi << ' ' << b << ' ' << c << ' ' << type << ' ' << id << '\n';
            ans[id] = DS.calc(b, c);
        }
    }

    for (int i = 1; i <= q; i++)
    {
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 4 ms 9744 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 13 ms 11028 KB Output is correct
8 Correct 13 ms 11116 KB Output is correct
9 Correct 13 ms 11092 KB Output is correct
10 Correct 9 ms 10452 KB Output is correct
11 Incorrect 12 ms 11092 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 51172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 51172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 4 ms 9744 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 13 ms 11028 KB Output is correct
8 Correct 13 ms 11116 KB Output is correct
9 Correct 13 ms 11092 KB Output is correct
10 Correct 9 ms 10452 KB Output is correct
11 Incorrect 12 ms 11092 KB Output isn't correct
12 Halted 0 ms 0 KB -