Submission #1271156

#TimeUsernameProblemLanguageResultExecution timeMemory
1271156quangthenpcExamination (JOI19_examination)C++20
0 / 100
705 ms1114112 KiB
/*,
    author: quangthenpc..
    i'm terribly bad at coding, tbh.
,*/
#include <bits/stdc++.h>
using namespace std;

#define inout freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout);
#define int long long
#define i64 int64_t
#define all(a) a.begin(), a.end()
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)a.size()

int stringToInt(string s) {
    int res = 0;
    for(int i = 1; i <= sz(s); i++) {
        res += (s[i - 1] - '0') * pow(10, sz(s) - i);
    }
    return res;
}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

const int MAXN = 2e5 + 2;
const int INF = LONG_MAX;

// --------------------------- //
int n, q;
vector<pii> s, t, sum;
vector<int> s1, t1, sum1;
// --------------------------- //

void solve(void) {
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        s.pb({a, i});
        t.pb({b, i});
        sum.pb({a + b, i});

        s1.pb(a);
        t1.pb(b);
        sum1.pb(a + b);
    }
    sort(all(s));
    sort(all(t));
    sort(all(sum));

    sort(all(s1));
    sort(all(t1));
    sort(all(sum1));

    string temp = "";
    for(int i = 0; i < n; i++) {
        temp += '0';
    }

    vector<string> check1(n, temp), check2(n, temp), check3(n, temp);
    for(int i = 0; i < n; i++) {
        if(i) {
            check1[i] = check1[i - 1];
            check2[i] = check2[i - 1];
            check3[i] = check3[i - 1];
        }
        check1[i][s[i].se] = '1';
        check2[i][t[i].se] = '1';
        check3[i][sum[i].se] = '1';
    }

    while(q--) {
        int x, y, z;
        cin >> x >> y >> z;

        auto itx = lower_bound(all(s1), x);
        auto ity = lower_bound(all(t1), y);
        auto itz = lower_bound(all(sum1), z);

        string x1, y1, z1;
        if(itx != s1.end()) {
            x1 = check1[n - 1 - (itx - s1.begin())];
        } else {
            x1 = temp;
        }

        if(ity != t1.end()) {
            y1 = check2[n - 1 - (ity - t1.begin())];
        } else {
            y1 = temp;
        }

        if(itz != sum1.end()) {
            z1 = check3[n - 1 - (itz - sum1.begin())];
        } else {
            z1 = temp;
        }

        int res = 0;
        for(int i = 0; i < n; i++) {
            if(x1[i] == '1' && y1[i] == '1' && z1[i] == '1') {
                res++;
            }
        }
        cout << res << '\n';
    }
}

signed main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // inout;

    solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...