Submission #926966

# Submission time Handle Problem Language Result Execution time Memory
926966 2024-02-14T05:59:13 Z gubshig Examination (JOI19_examination) C++17
20 / 100
152 ms 6088 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MX = 1e5 + 1e3;

struct BIT{
    int t[MX], sz = MX;

    BIT(){
        fill(t, t + MX, 0);
    }

    void update(int i, int v){
        while(i < MX){
            t[i] += v;
            i += (i & -i);
        }
    }

    int query(int i){
        int ret = 0;
        while(i){
            ret += t[i];
            i -= (i & -i);
        }
        return ret;
    }
};

int n, q, ans[MX];
bool flag[MX];
array<int, 3> s[MX];
array<int, 4> qs[MX];

void solvex(){
    sort(s + 1, s + 1 + n, [&](array<int, 3> a, array<int, 3> b){
        return a[0] > b[0];
    });
    sort(qs + 1, qs + 1 + q, [&](array<int, 4> a, array<int, 4> b){
        return a[0] > b[0];
    });

    BIT bit;
    int ptr = 1;
    for(int i = 1; i <= q; i++){
        while(ptr <= n && s[ptr][0] >= qs[i][0]){
            bit.update(s[ptr][2], 1);
            ptr++;
        }
        if(flag[qs[i][3]]) ans[qs[i][3]] += ptr - bit.query(qs[i][2] - 1) - 1;
    }
}

void solvey(){
    sort(s + 1, s + 1 + n, [&](array<int, 3> a, array<int, 3> b){
        return a[1] > b[1];
    });
    sort(qs + 1, qs + 1 + q, [&](array<int, 4> a, array<int, 4> b){
        return a[1] > b[1];
    });

    BIT bit, bitx;
    int ptr = 1;
    for(int i = 1; i <= q; i++){
        while(ptr <= n && s[ptr][1] >= qs[i][1]){
            bit.update(s[ptr][2], 1);
            bitx.update(s[ptr][0], 1);
            ptr++;
        }
        if(flag[qs[i][3]]) ans[qs[i][3]] += ptr - bit.query(qs[i][2] - 1) - 1;
        else ans[qs[i][3]] = ptr - bitx.query(qs[i][0] - 1) - 1;
    }
}

void solvez(){
    for(int i = 1; i <= q; i++){
        if(flag[qs[i][3]]) ans[qs[i][3]] -= n - qs[i][2] + 1;
    }
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    
    cin >> n >> q;
    vector<int> a, c;
    for(int i = 1; i <= n; i++){
        cin >> s[i][0] >> s[i][1];
        a.push_back(s[i][0]);
        c.push_back(s[i][0] + s[i][1]);
    }
    
    sort(a.begin(), a.end());
    a.resize(unique(a.begin(), a.end()) - a.begin());
    sort(c.begin(), c.end());
    c.resize(unique(c.begin(), c.end()) - c.begin());
    for(int i = 1; i <= n; i++){
        s[i][2] = lower_bound(c.begin(), c.end(), s[i][0] + s[i][1]) - c.begin() + 1;
        s[i][0] = lower_bound(a.begin(), a.end(), s[i][0]) - a.begin() + 1;
    }

    for(int i = 1; i <= q; i++){
        cin >> qs[i][0] >> qs[i][1] >> qs[i][2];
        flag[i] = qs[i][0] + qs[i][1] < qs[i][2];
        qs[i][0] = lower_bound(a.begin(), a.end(), qs[i][0]) - a.begin() + 1;
        qs[i][2] = lower_bound(c.begin(), c.end(), qs[i][2]) - c.begin() + 1;
        qs[i][3] = i;
    }

    solvex();
    solvey();
    solvez();

    for(int i = 1; i <= q; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 152 ms 5832 KB Output is correct
2 Correct 113 ms 5824 KB Output is correct
3 Correct 114 ms 5864 KB Output is correct
4 Correct 119 ms 5828 KB Output is correct
5 Correct 80 ms 5984 KB Output is correct
6 Correct 57 ms 5848 KB Output is correct
7 Correct 112 ms 6088 KB Output is correct
8 Correct 112 ms 5848 KB Output is correct
9 Correct 113 ms 5864 KB Output is correct
10 Correct 74 ms 5776 KB Output is correct
11 Correct 101 ms 5816 KB Output is correct
12 Correct 48 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 5832 KB Output is correct
2 Correct 113 ms 5824 KB Output is correct
3 Correct 114 ms 5864 KB Output is correct
4 Correct 119 ms 5828 KB Output is correct
5 Correct 80 ms 5984 KB Output is correct
6 Correct 57 ms 5848 KB Output is correct
7 Correct 112 ms 6088 KB Output is correct
8 Correct 112 ms 5848 KB Output is correct
9 Correct 113 ms 5864 KB Output is correct
10 Correct 74 ms 5776 KB Output is correct
11 Correct 101 ms 5816 KB Output is correct
12 Correct 48 ms 5592 KB Output is correct
13 Incorrect 134 ms 6088 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3160 KB Output isn't correct
2 Halted 0 ms 0 KB -