Submission #907740

# Submission time Handle Problem Language Result Execution time Memory
907740 2024-01-16T03:54:30 Z trMatherz Examination (JOI19_examination) C++17
0 / 100
2867 ms 738704 KB
#include <iostream> //cin, cout

/*
#include <fstream>
std::ifstream cin ("ex.in");
std::ofstream cout ("ex.out");
*/




// includes
#include <cmath> 
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>



//usings 
using namespace std;
using namespace __gnu_pbds;


// misc
#define ll long long
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; }
typedef uint64_t hash_t;

// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()


// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second

// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// maps
#define mii map<int, int>
#define mll map<ll, ll>

// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRE(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define FE(x, y) F(x, y + 1)
#define A(x, y) for(auto &x : y)

struct Ynode{
    Ynode *lc, *rc;
    int v;
    Ynode(){
        lc = nullptr; rc = nullptr; v = 0;
    }
};

struct Xnode{
    Xnode *lc, *rc;
    Ynode child;
    Xnode(){
        lc = nullptr; rc = nullptr; child = Ynode();
    }
};

void rad(Ynode *cur, int l, int r, int y, int v){
    if(l == r) {cur->v += v; return;}
    int m = (int) (((ll)l + r) / 2);
    if(y <= m){
        if(cur->lc == nullptr) cur->lc = new Ynode();
        rad(cur->lc, l, m, y, v);
    } else {
        if(cur->rc == nullptr) cur->rc = new Ynode();
        rad(cur->rc, m + 1, r, y, v);
    }
    int ret = 0;
    if(cur->lc != nullptr) ret += cur->lc->v;
    if(cur->rc != nullptr) ret += cur->rc->v;
    cur->v = ret;
}

void add(Xnode *cur, int l, int r, int x, int y, int v){
   
    rad(&cur->child, 0, 2'000'000'001, y, v);
    if(l == r) return;
    int m = (l + r) / 2;
    if(x <= m){
        if(cur->lc == nullptr) cur->lc = new Xnode();
        add(cur->lc, l, m, x, y, v);
    } else {
        if(cur->rc == nullptr) cur->rc = new Xnode();
        add(cur->rc, m + 1, r, x, y, v);
    }
}

int ret(Ynode *cur, int l, int r, int y){
    if(l > y) return 0;
    if(r <= y) return cur->v;
    int yet = 0;
    int m = (int) (((ll)l + r) / 2);
    if(cur->lc != nullptr) yet += ret(cur->lc, l, m, y);
    if(cur->rc != nullptr) yet += ret(cur->rc, m + 1, r, y);
    return yet;
}

int get(Xnode *cur, int l, int r, int x, int y){
    if(l > x) return 0;
    if(r <= x) return ret(&cur->child, 0, 2'000'000'001, y);
    int ret = 0;
    int m = (l + r) / 2;
    if(cur->lc != nullptr) ret += get(cur->lc, l, m, x, y);
    if(cur->rc != nullptr) ret += get(cur->rc, m + 1, r, x, y);
    return ret;
}


int main(){
    Xnode *root = new Xnode();
    int n, q; cin >> n >> q;
    vi ans(q);  
    vpii a(n);
    A(u, a) cin >> u.f >> u.s;
    sort(all(a), [](auto a, auto b){return a.f > b.f;});
    vpii o(n);
    F(i, n) o[i] = {a[i].s, i};
    sort(all(o), [](auto a, auto b){return a.f > b.f;});
    vector<array<int, 4>> todo(q);
    int count = 0;
    A(u, todo) {cin >> u[0] >> u[1] >> u[2]; u[3] = count++;}
    sort(all(todo), [](auto a, auto b){return a[1] > b[1];});
    int p = 0;
    auto fin = [&](int x){
        int l = 0, r = n - 1;
        while(l < r){
            int m = (l + r + 1) / 2;
            if(a[m].f >= x) l = m;
            else r = m - 1;
        }
        return l;
    };
    A(u, todo){
        while(p < n && o[p].f >= u[1]){
            add(root, 0, n - 1, o[p].s, 0, 1);
            add(root, 0, n - 1, o[p].s, a[o[p].s].f + a[o[p].s].s + 1, -1);
            p++;
        }
        int x = fin(u[0]);
        ans[u[3]] = get(root, 0, n - 1, x, u[2]);
    }
    A(u, ans) cout << u << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2867 ms 738140 KB Output is correct
2 Correct 2815 ms 738536 KB Output is correct
3 Correct 2825 ms 738704 KB Output is correct
4 Correct 1744 ms 394188 KB Output is correct
5 Correct 2146 ms 720212 KB Output is correct
6 Correct 1151 ms 254620 KB Output is correct
7 Correct 2676 ms 738324 KB Output is correct
8 Correct 2800 ms 738196 KB Output is correct
9 Correct 2714 ms 738212 KB Output is correct
10 Incorrect 1980 ms 719756 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2867 ms 738140 KB Output is correct
2 Correct 2815 ms 738536 KB Output is correct
3 Correct 2825 ms 738704 KB Output is correct
4 Correct 1744 ms 394188 KB Output is correct
5 Correct 2146 ms 720212 KB Output is correct
6 Correct 1151 ms 254620 KB Output is correct
7 Correct 2676 ms 738324 KB Output is correct
8 Correct 2800 ms 738196 KB Output is correct
9 Correct 2714 ms 738212 KB Output is correct
10 Incorrect 1980 ms 719756 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -