Submission #1273482

#TimeUsernameProblemLanguageResultExecution timeMemory
1273482thaibeo123Examination (JOI19_examination)C++17
100 / 100
735 ms60428 KiB
#include <bits/stdc++.h>
using namespace std;

#define NAME "BAI5"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 4e5 + 5;

struct Node {
    int x, y, z, id;
};

bool cmp(Node &a, Node &b) {
    return a.z > b.z;
}

int n, m, sz;
int ans[N];
vector<Node> v;
Node a[N];
vector<int> vals;
vector<int> pos[N], fen[N];

void fakeupdate(int x, int y) {
    for (int i = x; i <= sz; i += i & -i) {
        pos[i].pb(y);
    }
}

void fakeget(int x, int y) {
    for (int i = x; i > 0; i -= i & -i) {
        pos[i].pb(y);
    }
}

void compress() {
    for (int i = 1; i <= sz; i++) {
        pos[i].pb(-1e9);
        pos[i].pb(1e9);
        sort(all(pos[i]));
        pos[i].erase(unique(all(pos[i])), pos[i].end());
        fen[i].assign(pos[i].size(), 0);
    }
}

void update(int x, int y, int v) {
    for (int i = x; i <= sz; i += i & -i) {
        int cur = lower_bound(all(pos[i]), y) - pos[i].begin();
        for (int j = cur; j < (int)fen[i].size(); j += j & -j) {
            fen[i][j] += v;
        }
    }
}

int get(int x, int y) {
    int res = 0;
    for (int i = x; i > 0; i -= i & -i) {
        int cur = lower_bound(all(pos[i]), y) - pos[i].begin();
        for (int j = cur; j > 0; j -= j & -j) {
            res += fen[i][j];
        }
    }
    return res;
}

void preprocess() {
    for (auto &it : v) {
        it.x = upper_bound(all(vals), it.x) - vals.begin();
        fakeupdate(it.x, it.y);
    }
    for (int i = 1; i <= m; i++) {
        a[i].x = upper_bound(all(vals), a[i].x) - vals.begin();
        int x = a[i].x, y = a[i].y;
        fakeget(vals.size(), y - 1);
        fakeget(x - 1, y - 1);
    }
    compress();
}

void input() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int x, y, z;
        cin >> x >> y;
        z = x + y;
        vals.pb(x);
        v.pb({x, y, z, 0});
    }
    sort(all(v), cmp);
    for (int i = 1; i <= m; i++) {
        cin >> a[i].x >> a[i].y >> a[i].z;
        a[i].id = i;
        vals.pb(a[i].x);
    }
    sort(all(vals));
    vals.erase(unique(all(vals)), vals.end());
    sort(a + 1, a + 1 + m, cmp);
    sz = vals.size();
}

void solve() {
    preprocess();
    int j = 0;
    for (int i = 1; i <= m; i++) {
        while (j < (int)v.size() && v[j].z >= a[i].z) {
            update(v[j].x, v[j].y, 1);
            j++;
        }
        int x = a[i].x, y = a[i].y, id = a[i].id;
        ans[id] = j - get(x - 1, 1e9) - get(vals.size(), y - 1) + get(x - 1, y - 1);
    }
    for (int i = 1; i <= m; i++) {
        cout << ans[i] << "\n";
    }
}

signed main() {
    if (fopen(NAME".INP", "r")) {
        freopen(NAME".INP", "r", stdin);
        freopen(NAME".OUT", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        input();
        solve();
    }

    return 0;
}

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen(NAME".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen(NAME".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...