Submission #378056

#TimeUsernameProblemLanguageResultExecution timeMemory
378056penguinhackerExamination (JOI19_examination)C++14
100 / 100
434 ms19140 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN = 100000; int n, q, ans[mxN], bit[2 * mxN + 1]; void upd(int i, int inc) { for (++i; i <= 2 * mxN; i += i & -i) bit[i] += inc; } int qry(int i) { int res = 0; for (++i; i > 0; i -= i & -i) res += bit[i]; return res; } struct Query { int a, b, c, ind; bool operator<(const Query& o) const { if (a ^ o.a) return a > o.a; if (b ^ o.b) return b > o.b; if (c ^ o.c) return c > o.c; return ind < o.ind; } } qrys[2 * mxN]; void solve(int l = 0, int r = n + q - 1) { if (l == r) return; int mid = (l + r) / 2; solve(l, mid); solve(mid + 1, r); vector<Query> tmp; vector<int> rb; int i = l, j = mid + 1; for (; j <= r; ++j) { while(i <= mid && qrys[i].b >= qrys[j].b) { if (qrys[i].ind == -1) { upd(qrys[i].c, 1); rb.push_back(qrys[i].c); } tmp.push_back(qrys[i++]); } if (qrys[j].ind != -1) ans[qrys[j].ind] += qry(2 * mxN - 1) - qry(qrys[j].c - 1); tmp.push_back(qrys[j]); } while(i <= mid) tmp.push_back(qrys[i++]); assert(tmp.size() == r - l + 1); for (int i = l; i <= r; ++i) qrys[i] = tmp[i - l]; for (int i : rb) upd(i, -1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; qrys[i] = {a, b, a + b, -1}; } for (int i = 0; i < q; ++i) { int a, b, c; cin >> a >> b >> c; qrys[i + n] = {a, b, c, i}; } vector<int> da(n + q), db(n + q), dc(n + q); for (int i = 0; i < n + q; ++i) da[i] = qrys[i].a, db[i] = qrys[i].b, dc[i] = qrys[i].c; sort(da.begin(), da.end()); sort(db.begin(), db.end()); sort(dc.begin(), dc.end()); for (int i = 0; i < n + q; ++i) { qrys[i].a = lower_bound(da.begin(), da.end(), qrys[i].a) - da.begin(); qrys[i].b = lower_bound(db.begin(), db.end(), qrys[i].b) - db.begin(); qrys[i].c = lower_bound(dc.begin(), dc.end(), qrys[i].c) - dc.begin(); } sort(qrys, qrys + n + q); solve(); for (int i = 0; i < q; ++i) cout << ans[i] << "\n"; return 0; }

Compilation message (stderr)

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from examination.cpp:1:
examination.cpp: In function 'void solve(int, int)':
examination.cpp:55:20: warning: comparison of integer expressions of different signedness: 'std::vector<Query>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |  assert(tmp.size() == r - l + 1);
      |         ~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...