Submission #518656

# Submission time Handle Problem Language Result Execution time Memory
518656 2022-01-24T11:25:39 Z SmolBrain Examination (JOI19_examination) C++17
100 / 100
2228 ms 175440 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'
#define pb push_back
#define conts continue
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define ff first
#define ss second
#define ceil2(x,y) ((x+y-1) / (y))
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<" = "; print(x); cout << endl
#else
#define debug(x)
#endif

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define trav(i,a) for(auto &i : a)

bool iseven(ll n) {if ((n & 1) == 0) return true; return false;}

void print(ll t) {cout << t;}
void print(int t) {cout << t;}
void print(string t) {cout << t;}
void print(char t) {cout << t;}
void print(double t) {cout << t;}
void print(ld t) {cout << t;}

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(pair <T, V> p) {cout << "{"; print(p.ff); cout << ","; print(p.ss); cout << "}";}
template <class T> void print(vector <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(set <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(multiset <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T, class V> void print(map <T, V> v) {cout << "[ "; for (auto i : v) {print(i); cout << " ";} cout << "]";}

void usaco(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const int maxn = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = ll(1e18) + 5;

int cnt = 0;

template<typename T, int sp>
struct segtree {
    /*=======================================================*/

    struct data {
        Tree<pair<int, int>> os;
    };

    data neutral = {};

    void merge(data &curr, data &left, data &right) {

    }

    void create(int x, int lx, int rx, T v) {

    }

    void modify(int x, int lx, int rx, T v) {

    }

    /*=======================================================*/

    int siz = 1;
    vector<data> tr;

    segtree(int n) {
        init(n);
    }

    segtree() {

    };

    void init(int n) {
        while (siz < n) siz *= 2;
        tr.assign(2 * siz, neutral);
    }

    void build(vector<T> &a, int n, int x, int lx, int rx) {
        if (rx - lx == 1) {
            if (lx >= sp and lx < n) {
                create(x, lx, rx, a[lx]);
            }

            return;
        }

        int mid = (lx + rx) / 2;

        build(a, n, 2 * x + 1, lx, mid);
        build(a, n, 2 * x + 2, mid, rx);

        merge(tr[x], tr[2 * x + 1], tr[2 * x + 2]);
    }

    void build(vector<T> &a, int n) {
        build(a, n, 0, 0, siz);
    }

    void pupd(int i, T v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            tr[x].os.insert({v, cnt});
            cnt++;
            return;
        }

        int mid = (lx + rx) / 2;

        if (i < mid) {
            pupd(i, v, 2 * x + 1, lx, mid);
        }
        else {
            pupd(i, v, 2 * x + 2, mid, rx);
        }

        tr[x].os.insert({v, cnt});
    }

    void pupd(int i, T v) {
        pupd(i, v, 0, 0, siz);
    }

    int query(int l, int r, int k, int x, int lx, int rx) {
        if (lx >= r or rx <= l) return 0;
        if (lx >= l and rx <= r){
            auto &curr = tr[x].os;
            int less = curr.order_of_key({k, -inf1});
            int res = sz(curr) - less;
            return res;
        }

        int mid = (lx + rx) / 2;

        int curr;
        int left = query(l, r, k, 2 * x + 1, lx, mid);
        int right = query(l, r, k, 2 * x + 2, mid, rx);

        curr = left + right;
        return curr;
    }

    int query(int l, int r, int k) {
        return query(l, r + 1, k, 0, 0, siz);
    }
};

void solve(int test_case)
{
    int n, q; cin >> n >> q;
    vector<pair<int, int>> a(n);
    rep(i, n) cin >> a[i].ff >> a[i].ss;

    auto comp = [&](pair<int, int> &p1, pair<int, int> &p2) {
        if (p1.ff + p1.ss > p2.ff + p2.ss) {
            return true;
        }

        return false;
    };

    sort(all(a), comp);

    vector<array<int, 4>> queries(n);
    rep(i, q) {
        int x, y, z; cin >> x >> y >> z;
        queries[i] = {z, x, y, i};
    }

    sort(rall(queries));

    vector<int> b;
    rep(i, n) b.pb(a[i].ff);
    rep(i, q) b.pb(queries[i][1]);

    sort(all(b));
    auto it = unique(all(b));
    b.resize(it - b.begin());
    int siz = sz(b);

    segtree<int,0> st(siz + 5);
    int ptr = 0;
    vector<int> ans(q);

    rep(i, q) {
        auto [z, x, y, id] = queries[i];

        while (ptr < n) {
            int sum = a[ptr].ff + a[ptr].ss;
            if (sum < z) break;

            int idx = lower_bound(all(b), a[ptr].ff) - b.begin();
            st.pupd(idx, a[ptr].ss);

            ptr++;
        }

        x = lower_bound(all(b), x) - b.begin();
        int res = st.query(x, siz, y);
        ans[id] = res;
    }

    rep(i, q) cout << ans[i] << endl;
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;
    rep1(i, t) {
        solve(i);
    }

    return 0;
}

Compilation message

examination.cpp: In function 'void usaco(std::string)':
examination.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 18 ms 4500 KB Output is correct
8 Correct 17 ms 4556 KB Output is correct
9 Correct 16 ms 4548 KB Output is correct
10 Correct 15 ms 4564 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 17 ms 4668 KB Output is correct
14 Correct 16 ms 4664 KB Output is correct
15 Correct 16 ms 4692 KB Output is correct
16 Correct 6 ms 1272 KB Output is correct
17 Correct 15 ms 4812 KB Output is correct
18 Correct 7 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1761 ms 141772 KB Output is correct
2 Correct 1757 ms 141784 KB Output is correct
3 Correct 1739 ms 141708 KB Output is correct
4 Correct 941 ms 141756 KB Output is correct
5 Correct 324 ms 37356 KB Output is correct
6 Correct 303 ms 36636 KB Output is correct
7 Correct 1811 ms 144088 KB Output is correct
8 Correct 1674 ms 144180 KB Output is correct
9 Correct 1646 ms 144000 KB Output is correct
10 Correct 206 ms 30912 KB Output is correct
11 Correct 1020 ms 143296 KB Output is correct
12 Correct 391 ms 36240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1761 ms 141772 KB Output is correct
2 Correct 1757 ms 141784 KB Output is correct
3 Correct 1739 ms 141708 KB Output is correct
4 Correct 941 ms 141756 KB Output is correct
5 Correct 324 ms 37356 KB Output is correct
6 Correct 303 ms 36636 KB Output is correct
7 Correct 1811 ms 144088 KB Output is correct
8 Correct 1674 ms 144180 KB Output is correct
9 Correct 1646 ms 144000 KB Output is correct
10 Correct 206 ms 30912 KB Output is correct
11 Correct 1020 ms 143296 KB Output is correct
12 Correct 391 ms 36240 KB Output is correct
13 Correct 2066 ms 144476 KB Output is correct
14 Correct 2228 ms 144416 KB Output is correct
15 Correct 1694 ms 144460 KB Output is correct
16 Correct 1179 ms 143756 KB Output is correct
17 Correct 380 ms 37772 KB Output is correct
18 Correct 299 ms 36744 KB Output is correct
19 Correct 1962 ms 144352 KB Output is correct
20 Correct 2029 ms 144388 KB Output is correct
21 Correct 1832 ms 144480 KB Output is correct
22 Correct 196 ms 31124 KB Output is correct
23 Correct 983 ms 143320 KB Output is correct
24 Correct 385 ms 36268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 18 ms 4500 KB Output is correct
8 Correct 17 ms 4556 KB Output is correct
9 Correct 16 ms 4548 KB Output is correct
10 Correct 15 ms 4564 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 17 ms 4668 KB Output is correct
14 Correct 16 ms 4664 KB Output is correct
15 Correct 16 ms 4692 KB Output is correct
16 Correct 6 ms 1272 KB Output is correct
17 Correct 15 ms 4812 KB Output is correct
18 Correct 7 ms 1364 KB Output is correct
19 Correct 1761 ms 141772 KB Output is correct
20 Correct 1757 ms 141784 KB Output is correct
21 Correct 1739 ms 141708 KB Output is correct
22 Correct 941 ms 141756 KB Output is correct
23 Correct 324 ms 37356 KB Output is correct
24 Correct 303 ms 36636 KB Output is correct
25 Correct 1811 ms 144088 KB Output is correct
26 Correct 1674 ms 144180 KB Output is correct
27 Correct 1646 ms 144000 KB Output is correct
28 Correct 206 ms 30912 KB Output is correct
29 Correct 1020 ms 143296 KB Output is correct
30 Correct 391 ms 36240 KB Output is correct
31 Correct 2066 ms 144476 KB Output is correct
32 Correct 2228 ms 144416 KB Output is correct
33 Correct 1694 ms 144460 KB Output is correct
34 Correct 1179 ms 143756 KB Output is correct
35 Correct 380 ms 37772 KB Output is correct
36 Correct 299 ms 36744 KB Output is correct
37 Correct 1962 ms 144352 KB Output is correct
38 Correct 2029 ms 144388 KB Output is correct
39 Correct 1832 ms 144480 KB Output is correct
40 Correct 196 ms 31124 KB Output is correct
41 Correct 983 ms 143320 KB Output is correct
42 Correct 385 ms 36268 KB Output is correct
43 Correct 1992 ms 175196 KB Output is correct
44 Correct 1974 ms 175388 KB Output is correct
45 Correct 2199 ms 175356 KB Output is correct
46 Correct 1197 ms 175212 KB Output is correct
47 Correct 393 ms 38312 KB Output is correct
48 Correct 288 ms 36536 KB Output is correct
49 Correct 2068 ms 175440 KB Output is correct
50 Correct 1882 ms 175288 KB Output is correct
51 Correct 1809 ms 175364 KB Output is correct
52 Correct 383 ms 31788 KB Output is correct
53 Correct 972 ms 175116 KB Output is correct