Submission #613080

#TimeUsernameProblemLanguageResultExecution timeMemory
613080talant117408Examination (JOI19_examination)C++17
22 / 100
193 ms11616 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Общий файл. 
#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

void solve(int test) {
    int n, q;
    cin >> n >> q;
    vector <int> a(n), b(n);
    vector <pair <pii, pii>> queries(q);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < q; i++) {
        auto &to = queries[i];
        cin >> to.first.first >> to.first.second >> to.second.first;
        to.second.second = i;
    }
    if (n <= 3000 && q <= 3000) {
        for (auto to : queries) {
            auto x = to.first.first, y = to.first.second, z = to.second.first;
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] >= x && b[i] >= y && a[i] + b[i] >= z) {
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }
    else {
        vector <int> inds(n);
        iota(all(inds), 0);
        sort(all(inds), [&](int i, int j) {
            return a[i] < a[j];
        });
        int i = n - 1;
        ordered_set st;
        sort(rall(queries));
        vector <int> ans(q);
        for (auto to : queries) {
            auto x = to.first.first, y = to.first.second, z = to.second.first;
            auto ind = to.second.second;
            while (i >= 0 && a[inds[i]] >= x) {
                st.insert(b[inds[i--]]);
            }
            ans[ind] = sz(st) - st.order_of_key(y);
        }
        for (auto to : ans) cout << to << endl;
    }
}
 
int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
    
    return 0;
}

Compilation message (stderr)

examination.cpp: In function 'void solve(int)':
examination.cpp:61:59: warning: unused variable 'z' [-Wunused-variable]
   61 |             auto x = to.first.first, y = to.first.second, z = to.second.first;
      |                                                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...