제출 #1149605

#제출 시각아이디문제언어결과실행 시간메모리
1149605minggaExamination (JOI19_examination)C++20
100 / 100
262 ms45976 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;

const int N = 1e5 + 7;
int n, q, ans[N];

struct mark {
    int s, t, tot;
} d[N];

struct query {
    int x, y, z, id;
} e[N];

vector<mark> ev[N * 2], ev2[N * 2];
vector<query> que[N * 2], que2[N * 2];

vector<int> dx, dy, ds;
int get_x(int x) {
    return lower_bound(all(dx), x) - dx.begin() + 1;
}
int get_y(int x) {
    return lower_bound(all(dy), x) - dy.begin() + 1;
}
int get_s(int x) {
    return lower_bound(all(ds), x) - ds.begin() + 1;
}

struct BIT {
    vector<int> bit;
    int n;
    BIT() {}
    BIT(int n) : n(n) {
        bit.resize(n + 5, 0);
    }
    void update(int u, int x) {
        for(u; u <= n; u += (u & -u)) bit[u] += x;
    }
    int get(int u) {
        int ans = 0;
        for(u; u > 0; u -= (u & -u)) ans += bit[u];
        return ans; 
    }
    int get(int l, int r) {
        return get(r) - get(l - 1);
    }
} bitx, bity;

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    #define task ""
    if(fopen(task ".INP", "r")) {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        cin >> d[i].s >> d[i].t;
        d[i].tot = d[i].s + d[i].t;
        dx.pb(d[i].s);
        dy.pb(d[i].t);
        ds.pb(d[i].tot);
    }
    for(int i = 1; i <= q; i++) {
        int x, y, z; cin >> x >> y >> z;
        dx.pb(x); dy.pb(y); ds.pb(z);
        e[i] = {x, y, z, i};
    }
    sort(all(dx));
    dx.erase(unique(all(dx)), dx.end());
    sort(all(dy));
    dy.erase(unique(all(dy)), dy.end());
    sort(all(ds));
    ds.erase(unique(all(ds)), ds.end());
    for(int i = 1; i <= n; i++) {
        d[i] = {get_x(d[i].s), get_y(d[i].t), get_s(d[i].tot)};
        ev[d[i].tot].pb(d[i]);
        ev2[d[i].s].pb(d[i]);
    }
    for(int i = 1; i <= q; i++) {
        bool ok = 0;
        if(e[i].x + e[i].y < e[i].z) {
            ok = 1;
        }
        e[i] = {get_x(e[i].x), get_y(e[i].y), get_s(e[i].z), i};
        if(ok) que[e[i].z].pb(e[i]);
        else que2[e[i].x].pb(e[i]);
    }
    int cur = 0;
    bitx = BIT(2 * n);
    bity = BIT(2 * n);
    for(int i = 2 * n; i > 0; i--) {
        cur += sz(ev[i]);
        for(auto x: ev[i]) {
            bitx.update(x.s, 1);
            bity.update(x.t, 1);
        }
        for(auto x: que[i]) {
            ans[x.id] = bitx.get(x.x, n * 2) + bity.get(x.y, n * 2) - cur;
        }
    }
    bity = BIT(2 * n);
    for(int i = 2 * n; i > 0; i--) {
        for(auto x: ev2[i]) {
            bity.update(x.t, 1);
        }
        for(auto x: que2[i]) {
            ans[x.id] = bity.get(x.y, n * 2);
        }
    }
    for(int i = 1; i <= q; i++) cout << ans[i] << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

컴파일 시 표준 에러 (stderr) 메시지

examination.cpp: In function 'int main()':
examination.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task ".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...