Submission #261622

# Submission time Handle Problem Language Result Execution time Memory
261622 2020-08-11T22:58:39 Z doowey Examination (JOI19_examination) C++14
100 / 100
1913 ms 306148 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

struct P{
    int x;
    int y;
    int sum;
};

const int N = (int)1e5 + 100;

vector<pii> S[N];

int zsz, ysz;
struct Segt{
    struct Node{
        int nex_l;
        int nex_r;
        int value;
    };
    vector<Node> cur;
    int id;
    int add_node(){
        cur.push_back({-1, -1, 0});
        id ++ ;
        return id - 1;
    }
    void upd(int node, int cl, int cr, int pos){
        cur[node].value ++ ;
        if(cl == cr)
            return;
        int mid = (cl + cr) / 2;
        if(mid >= pos){
            if(cur[node].nex_l == -1){
                int nxi = add_node();
                cur[node].nex_l = nxi;
            }
            upd(cur[node].nex_l, cl, mid, pos);

        }
        else{
            if(cur[node].nex_r == -1){
                int nxi = add_node();
                cur[node].nex_r = nxi;
            }
            upd(cur[node].nex_r, mid + 1, cr, pos);
        }
    }
    int get(int node, int cl, int cr, int tl, int tr){
        if(cr < tl || cl > tr || node == -1)
            return 0;
        if(cl >= tl && cr <= tr)
            return cur[node].value;
        int mid = (cl + cr) / 2;
        return get(cur[node].nex_l, cl, mid, tl, tr) + get(cur[node].nex_r, mid + 1, cr, tl, tr);
    }
};

Segt F[N * 4 + 512];

void update(int node, int cl, int cr, int pos, int vv){
    if(F[node].cur.empty())
        F[node].add_node();
    F[node].upd(0, 0, zsz - 1, vv);
    if(cl == cr)
        return;
    int mid = (cl + cr) / 2;
    if(mid >= pos)
        update(node * 2, cl, mid, pos, vv);
    else
        update(node * 2 + 1, mid + 1, cr, pos, vv);
}

int query(int node, int cl, int cr, int tl, int tr, int nl, int nr){
    if(cr < tl || cl > tr) return 0;
    if(cl >= tl && cr <= tr){
        if(F[node].cur.empty()) return 0;
        else return F[node].get(0, 0, zsz - 1, nl, nr);
    }
    int mid = (cl + cr) / 2;
    return query(node * 2, cl, mid, tl, tr, nl, nr) + query(node * 2 + 1, mid + 1, cr, tl, tr, nl, nr);
}

struct Query{
    int yy;
    int zz;
    int id;
};

vector<Query> tq[N];

int res[N];

int main(){
    fastIO;
    int n, q;
    cin >> n >> q;
    vector<P> st;
    int a, b;
    vector<int> xx, yy, zz;
    for(int i = 1; i <= n; i ++ ){
        cin >> a >> b;
        st.push_back({a, b, a + b});
        xx.push_back(a);
        yy.push_back(b);
        zz.push_back(a + b);
    }
    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());
    sort(zz.begin(), zz.end());
    xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
    yy.resize(unique(yy.begin(), yy.end()) - yy.begin());
    zz.resize(unique(zz.begin(), zz.end()) - zz.begin());
    ysz = yy.size();
    zsz = zz.size();
    for(auto &p : st){
        p.x = lower_bound(xx.begin(), xx.end(), p.x) - xx.begin();
        p.y = lower_bound(yy.begin(), yy.end(), p.y) - yy.begin();
        p.sum = lower_bound(zz.begin(), zz.end(), p.sum) - zz.begin();
        S[p.x].push_back(mp(p.y, p.sum));
    }
    int c;
    for(int i = 0; i < q; i ++ ){
        cin >> a >> b >> c;
        a = lower_bound(xx.begin(), xx.end(), a) - xx.begin();
        b = lower_bound(yy.begin(), yy.end(), b) - yy.begin();
        c = lower_bound(zz.begin(), zz.end(), c) - zz.begin();
        tq[a].push_back({b, c, i});
    }
    for(int i = N - 1; i >= 0 ; i -- ){
        for(auto x : S[i]){
            update(1, 0, ysz - 1, x.fi, x.se);
        }
        for(auto x : tq[i]){
            res[x.id] = query(1, 0, ysz - 1, x.yy, ysz - 1, x.zz, zsz - 1);
        }
    }
    for(int i = 0 ; i < q; i ++ ){
        cout << res[i] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 17536 KB Output is correct
2 Correct 12 ms 17664 KB Output is correct
3 Correct 12 ms 17536 KB Output is correct
4 Correct 13 ms 17536 KB Output is correct
5 Correct 12 ms 17536 KB Output is correct
6 Correct 13 ms 17536 KB Output is correct
7 Correct 32 ms 22272 KB Output is correct
8 Correct 32 ms 22264 KB Output is correct
9 Correct 37 ms 22144 KB Output is correct
10 Correct 20 ms 18944 KB Output is correct
11 Correct 27 ms 19960 KB Output is correct
12 Correct 16 ms 17920 KB Output is correct
13 Correct 30 ms 22264 KB Output is correct
14 Correct 32 ms 22272 KB Output is correct
15 Correct 30 ms 22136 KB Output is correct
16 Correct 25 ms 20000 KB Output is correct
17 Correct 18 ms 18176 KB Output is correct
18 Correct 14 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1483 ms 255168 KB Output is correct
2 Correct 1496 ms 255524 KB Output is correct
3 Correct 1400 ms 254964 KB Output is correct
4 Correct 250 ms 47036 KB Output is correct
5 Correct 1004 ms 101676 KB Output is correct
6 Correct 101 ms 25132 KB Output is correct
7 Correct 1402 ms 254756 KB Output is correct
8 Correct 1416 ms 255392 KB Output is correct
9 Correct 1502 ms 255004 KB Output is correct
10 Correct 1014 ms 96784 KB Output is correct
11 Correct 183 ms 28716 KB Output is correct
12 Correct 69 ms 25000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1483 ms 255168 KB Output is correct
2 Correct 1496 ms 255524 KB Output is correct
3 Correct 1400 ms 254964 KB Output is correct
4 Correct 250 ms 47036 KB Output is correct
5 Correct 1004 ms 101676 KB Output is correct
6 Correct 101 ms 25132 KB Output is correct
7 Correct 1402 ms 254756 KB Output is correct
8 Correct 1416 ms 255392 KB Output is correct
9 Correct 1502 ms 255004 KB Output is correct
10 Correct 1014 ms 96784 KB Output is correct
11 Correct 183 ms 28716 KB Output is correct
12 Correct 69 ms 25000 KB Output is correct
13 Correct 1618 ms 255676 KB Output is correct
14 Correct 1634 ms 255536 KB Output is correct
15 Correct 1456 ms 255152 KB Output is correct
16 Correct 329 ms 47576 KB Output is correct
17 Correct 1173 ms 102664 KB Output is correct
18 Correct 109 ms 25132 KB Output is correct
19 Correct 1658 ms 256296 KB Output is correct
20 Correct 1579 ms 256036 KB Output is correct
21 Correct 1642 ms 255532 KB Output is correct
22 Correct 949 ms 97176 KB Output is correct
23 Correct 177 ms 28716 KB Output is correct
24 Correct 68 ms 25004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 17536 KB Output is correct
2 Correct 12 ms 17664 KB Output is correct
3 Correct 12 ms 17536 KB Output is correct
4 Correct 13 ms 17536 KB Output is correct
5 Correct 12 ms 17536 KB Output is correct
6 Correct 13 ms 17536 KB Output is correct
7 Correct 32 ms 22272 KB Output is correct
8 Correct 32 ms 22264 KB Output is correct
9 Correct 37 ms 22144 KB Output is correct
10 Correct 20 ms 18944 KB Output is correct
11 Correct 27 ms 19960 KB Output is correct
12 Correct 16 ms 17920 KB Output is correct
13 Correct 30 ms 22264 KB Output is correct
14 Correct 32 ms 22272 KB Output is correct
15 Correct 30 ms 22136 KB Output is correct
16 Correct 25 ms 20000 KB Output is correct
17 Correct 18 ms 18176 KB Output is correct
18 Correct 14 ms 17920 KB Output is correct
19 Correct 1483 ms 255168 KB Output is correct
20 Correct 1496 ms 255524 KB Output is correct
21 Correct 1400 ms 254964 KB Output is correct
22 Correct 250 ms 47036 KB Output is correct
23 Correct 1004 ms 101676 KB Output is correct
24 Correct 101 ms 25132 KB Output is correct
25 Correct 1402 ms 254756 KB Output is correct
26 Correct 1416 ms 255392 KB Output is correct
27 Correct 1502 ms 255004 KB Output is correct
28 Correct 1014 ms 96784 KB Output is correct
29 Correct 183 ms 28716 KB Output is correct
30 Correct 69 ms 25000 KB Output is correct
31 Correct 1618 ms 255676 KB Output is correct
32 Correct 1634 ms 255536 KB Output is correct
33 Correct 1456 ms 255152 KB Output is correct
34 Correct 329 ms 47576 KB Output is correct
35 Correct 1173 ms 102664 KB Output is correct
36 Correct 109 ms 25132 KB Output is correct
37 Correct 1658 ms 256296 KB Output is correct
38 Correct 1579 ms 256036 KB Output is correct
39 Correct 1642 ms 255532 KB Output is correct
40 Correct 949 ms 97176 KB Output is correct
41 Correct 177 ms 28716 KB Output is correct
42 Correct 68 ms 25004 KB Output is correct
43 Correct 1913 ms 305940 KB Output is correct
44 Correct 1848 ms 305768 KB Output is correct
45 Correct 1761 ms 305932 KB Output is correct
46 Correct 363 ms 54428 KB Output is correct
47 Correct 1285 ms 145836 KB Output is correct
48 Correct 109 ms 25000 KB Output is correct
49 Correct 1853 ms 305576 KB Output is correct
50 Correct 1894 ms 306148 KB Output is correct
51 Correct 1869 ms 305648 KB Output is correct
52 Correct 1206 ms 143012 KB Output is correct
53 Correct 192 ms 31400 KB Output is correct