Submission #208198

# Submission time Handle Problem Language Result Execution time Memory
208198 2020-03-10T08:43:59 Z paradox Examination (JOI19_examination) C++17
100 / 100
620 ms 37856 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define vi vector<int>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
typedef long long ll;
typedef short inth;
 
const int N = 8e5;
const int M = N + 7;
const int K = 2e5;
const int MOD = 1e9 + 7;
const ll INF = 1e16 + 17;

map<int, int> px, py;

struct Point {
    int x, y;
    int power;
    int id;

    int comx, comy;

    Point(int x, int y, int id, int new_power = -1) : 
            x(x), y(y), power(new_power), id(id), comx(0), comy(0) {
        if (new_power == -1)
            power = x + y;
    };

    void compress() {
        comx = px[x];
        comy = py[y];
    }
};

vector<Point> p, w[2];

int n, m;

inline void read() {
    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
        int cx, cy;
        scanf("%d %d", &cx, &cy);

        p.pb(Point(cx, cy, i));
    }

    for (int i = 1; i <= m; ++i) {
        int cx, cy, cs;
        scanf("%d %d %d", &cx, &cy, &cs);

        if (cx + cy >= cs)
            w[0].pb(Point(cx, cy, i, cs));
        else
            w[1].pb(Point(cx, cy, i, cs));
    }
}

inline void compress() {
    vector<int> ordx, ordy;

    for (int i = 0; i < n; ++i) {
        ordx.pb(p[i].x);
        ordy.pb(p[i].y);
    }

    for (int j = 0; j < 2; ++j)
        for (int i = 0; i < sz(w[j]); ++i) {
            ordx.pb(w[j][i].x);
            ordy.pb(w[j][i].y);
        }

    sort(all(ordx));
    sort(all(ordy));

    int timx = 0, timy = 0;
    for (int i = 0; i < sz(ordx); ++i) {
        if (!i || ordx[i] != ordx[i - 1])
            px[ordx[i]] = ++timx;
        if (!i || ordy[i] != ordy[i - 1])
            py[ordy[i]] = ++timy;
    }

    for (int i = 0; i < n; ++i)
        p[i].compress();
    for (int i = 0; i < sz(w[0]); ++i)
        w[0][i].compress();
    for (int i = 0; i < sz(w[1]); ++i)
        w[1][i].compress();
}

struct Tree {
    int g[M];

    void build() {
        for (int i = 0; i < M; ++i)
            g[i] = 0;
    }

    void upd(int pos, int val, int v = 1, int tl = 1, int tr = K) {
        if (tl == tr) {
            g[v] += val;
            return;
        }

        int tm = (tl + tr) >> 1;

        if (pos <= tm)
            upd(pos, val, v << 1, tl, tm);
        else
            upd(pos, val, v << 1 | 1, tm + 1, tr);

        g[v] = g[v << 1] + g[v << 1 | 1];
    }

    int get(int l, int r, int v = 1, int tl = 1, int tr = K) {
        if (tr < l || r < tl)
            return 0;
        
        if (l <= tl && tr <= r)
            return g[v];
        
        int tm = (tl + tr) >> 1;
        
        int f = get(l, r, v << 1, tl, tm);
        int s = get(l, r, v << 1 | 1, tm + 1, tr);

        return f + s;
    }

} tree[2];

inline bool cmpX(const Point& a, const Point& b) {
    return a.x > b.x;
}

int ans[M];

inline void solve1() {
    sort(w[0].begin(), w[0].end(), cmpX);
    sort(all(p), cmpX);

    int j = 0;
    tree[0].build();

    for (int i = 0; i < sz(w[0]); ++i) {
        while (j < sz(p) && p[j].x >= w[0][i].x) {
            tree[0].upd(p[j].comy, 1);
            ++j;
        }

        int res = tree[0].get(w[0][i].comy, K);

        ans[w[0][i].id] = res;
    }
}

inline bool cmpPower(const Point& a, const Point& b) {
    return a.power > b.power;
}

inline void solve2() {
    sort(w[1].begin(), w[1].end(), cmpPower);
    sort(all(p), cmpPower);

    int j = 0;
    tree[0].build();
    tree[1].build();

    for (int i = 0; i < sz(w[1]); ++i) {
        while (j < sz(p) && p[j].power >= w[1][i].power) {

            tree[0].upd(p[j].comx, 1);
            tree[1].upd(p[j].comy, 1);

            ++j;
        }

        int res = tree[0].get(1, w[1][i].comx - 1) + tree[1].get(1, w[1][i].comy - 1);

        ans[w[1][i].id] = j - res;

    }
}

inline void out() {
    for (int i = 1; i <= m; ++i)
        printf("%d\n", ans[i]);
}

int main() {

    read();

    compress();
    
    solve1();
    solve2();

    out();

    return 0;
}

Compilation message

examination.cpp: In function 'void read()':
examination.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &cx, &cy);
         ~~~~~^~~~~~~~~~~~~~~~~~~
examination.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &cx, &cy, &cs);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6520 KB Output is correct
2 Correct 8 ms 6520 KB Output is correct
3 Correct 8 ms 6520 KB Output is correct
4 Correct 8 ms 6520 KB Output is correct
5 Correct 9 ms 6648 KB Output is correct
6 Correct 9 ms 6520 KB Output is correct
7 Correct 18 ms 7544 KB Output is correct
8 Correct 18 ms 7548 KB Output is correct
9 Correct 18 ms 7544 KB Output is correct
10 Correct 15 ms 7160 KB Output is correct
11 Correct 15 ms 7160 KB Output is correct
12 Correct 12 ms 6904 KB Output is correct
13 Correct 17 ms 7544 KB Output is correct
14 Correct 17 ms 7544 KB Output is correct
15 Correct 17 ms 7544 KB Output is correct
16 Correct 14 ms 7160 KB Output is correct
17 Correct 15 ms 7160 KB Output is correct
18 Correct 11 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 21980 KB Output is correct
2 Correct 368 ms 21976 KB Output is correct
3 Correct 365 ms 21976 KB Output is correct
4 Correct 222 ms 17884 KB Output is correct
5 Correct 231 ms 18084 KB Output is correct
6 Correct 129 ms 12380 KB Output is correct
7 Correct 337 ms 21088 KB Output is correct
8 Correct 330 ms 21084 KB Output is correct
9 Correct 292 ms 20184 KB Output is correct
10 Correct 227 ms 17744 KB Output is correct
11 Correct 210 ms 17760 KB Output is correct
12 Correct 109 ms 11992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 21980 KB Output is correct
2 Correct 368 ms 21976 KB Output is correct
3 Correct 365 ms 21976 KB Output is correct
4 Correct 222 ms 17884 KB Output is correct
5 Correct 231 ms 18084 KB Output is correct
6 Correct 129 ms 12380 KB Output is correct
7 Correct 337 ms 21088 KB Output is correct
8 Correct 330 ms 21084 KB Output is correct
9 Correct 292 ms 20184 KB Output is correct
10 Correct 227 ms 17744 KB Output is correct
11 Correct 210 ms 17760 KB Output is correct
12 Correct 109 ms 11992 KB Output is correct
13 Correct 423 ms 22176 KB Output is correct
14 Correct 390 ms 25188 KB Output is correct
15 Correct 374 ms 24412 KB Output is correct
16 Correct 243 ms 20268 KB Output is correct
17 Correct 248 ms 20200 KB Output is correct
18 Correct 135 ms 16736 KB Output is correct
19 Correct 421 ms 25156 KB Output is correct
20 Correct 400 ms 25056 KB Output is correct
21 Correct 379 ms 24548 KB Output is correct
22 Correct 220 ms 19424 KB Output is correct
23 Correct 210 ms 19676 KB Output is correct
24 Correct 110 ms 13020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6520 KB Output is correct
2 Correct 8 ms 6520 KB Output is correct
3 Correct 8 ms 6520 KB Output is correct
4 Correct 8 ms 6520 KB Output is correct
5 Correct 9 ms 6648 KB Output is correct
6 Correct 9 ms 6520 KB Output is correct
7 Correct 18 ms 7544 KB Output is correct
8 Correct 18 ms 7548 KB Output is correct
9 Correct 18 ms 7544 KB Output is correct
10 Correct 15 ms 7160 KB Output is correct
11 Correct 15 ms 7160 KB Output is correct
12 Correct 12 ms 6904 KB Output is correct
13 Correct 17 ms 7544 KB Output is correct
14 Correct 17 ms 7544 KB Output is correct
15 Correct 17 ms 7544 KB Output is correct
16 Correct 14 ms 7160 KB Output is correct
17 Correct 15 ms 7160 KB Output is correct
18 Correct 11 ms 6904 KB Output is correct
19 Correct 364 ms 21980 KB Output is correct
20 Correct 368 ms 21976 KB Output is correct
21 Correct 365 ms 21976 KB Output is correct
22 Correct 222 ms 17884 KB Output is correct
23 Correct 231 ms 18084 KB Output is correct
24 Correct 129 ms 12380 KB Output is correct
25 Correct 337 ms 21088 KB Output is correct
26 Correct 330 ms 21084 KB Output is correct
27 Correct 292 ms 20184 KB Output is correct
28 Correct 227 ms 17744 KB Output is correct
29 Correct 210 ms 17760 KB Output is correct
30 Correct 109 ms 11992 KB Output is correct
31 Correct 423 ms 22176 KB Output is correct
32 Correct 390 ms 25188 KB Output is correct
33 Correct 374 ms 24412 KB Output is correct
34 Correct 243 ms 20268 KB Output is correct
35 Correct 248 ms 20200 KB Output is correct
36 Correct 135 ms 16736 KB Output is correct
37 Correct 421 ms 25156 KB Output is correct
38 Correct 400 ms 25056 KB Output is correct
39 Correct 379 ms 24548 KB Output is correct
40 Correct 220 ms 19424 KB Output is correct
41 Correct 210 ms 19676 KB Output is correct
42 Correct 110 ms 13020 KB Output is correct
43 Correct 620 ms 37804 KB Output is correct
44 Correct 607 ms 37728 KB Output is correct
45 Correct 616 ms 37856 KB Output is correct
46 Correct 312 ms 26848 KB Output is correct
47 Correct 325 ms 26848 KB Output is correct
48 Correct 148 ms 16612 KB Output is correct
49 Correct 597 ms 37816 KB Output is correct
50 Correct 576 ms 37476 KB Output is correct
51 Correct 546 ms 37816 KB Output is correct
52 Correct 309 ms 26596 KB Output is correct
53 Correct 287 ms 25648 KB Output is correct