Submission #518655

#TimeUsernameProblemLanguageResultExecution timeMemory
518655SmolBrainExamination (JOI19_examination)C++17
0 / 100
1910 ms144304 KiB
#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; 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, i}); 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, i}); } 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...