Submission #1260709

#TimeUsernameProblemLanguageResultExecution timeMemory
1260709tminhExamination (JOI19_examination)C++20
100 / 100
1488 ms692720 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 2e5 + 5; const ll oo = 1e18; bool START; int n, q; vector<int> arr; pii a[N]; struct node { int c, a, b, id; node(int c_, int a_, int b_, int id_) : c(c_), a(a_), b(b_), id(id_) {} bool operator<(const node &other) const { if (c == other.c) return id < other.id; return c > other.c; } }; vector<node> sw; const int base = 31; struct trie { struct node { node* child[2]; int cnt; node() { child[0] = child[1] = nullptr; cnt = 0; } }; node *root = new node(); int sz = 0; void add(const int x) { node* p = root; ++sz; for (int i = base; i >= 0; --i) { int bit = (x >> i) & 1; if (p->child[bit] == nullptr) p->child[bit] = new node(); p = p->child[bit]; ++p->cnt; } } int get(int x) { int ans = 0; node* p = root; for (int i = base; i >= 0; --i) { int bit = (x >> i) & 1; int bit0 = (p->child[0] ? p->child[0]->cnt : 0); if (bit) ans += bit0; if (p->child[bit] == nullptr) break; p = p->child[bit]; } return sz - ans; } }; int m; struct BIT { int id = 0; trie bit[N]; void add(int idx, int val) { idx = lower_bound(vall(arr), idx) - arr.begin() + 1; for (; idx <= m; idx += idx & -idx) bit[idx].add(val); } int get(int idx, int val) { int ans = 0; idx = lower_bound(vall(arr), idx) - arr.begin() + 1; for (; idx > 0; idx -= idx & -idx) ans += bit[idx].get(val); return ans; } int get(int l, int r, int val) { return get(r, val) - get(l - 1, val); } } bit; int ans[N]; inline void solve() { sort(vall(arr)); arr.erase(unique(vall(arr)), arr.end()); m = sze(arr); sort(vall(sw)); for (auto[c, a, b, id] : sw) { if (!id) { bit.add(a, b); continue; } ans[id] = bit.get(a, arr.back(), b); } for (int i = 1; i <= q; ++i) cout << ans[i] << endl; } inline void input() { cin >> n >> q; for (int i = 1; i <= n; ++i) { cin >> a[i].fi >> a[i].se; arr.pb(a[i].fi); sw.pb(node(a[i].fi + a[i].se, a[i].fi, a[i].se, 0)); } for (int i = 1; i <= q; ++i) { int a, b, c; cin >> a >> b >> c; sw.pb(node(c, a, b, i)); arr.pb(a - 1); } return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:137:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         freopen(task ".out", "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...