Submission #997871

#TimeUsernameProblemLanguageResultExecution timeMemory
997871vjudge1Examination (JOI19_examination)C++17
100 / 100
441 ms39224 KiB
#include <iostream> #include <vector> #include <array> #include <map> #include <algorithm> #define ll long long using namespace std; map <ll, ll> mp; vector <array<ll, 4>> Q; ll n, q, a, b, c, F[100000]; struct BIT{ vector <ll> val{vector <ll> (200001, 0)}; vector <ll> lazy{vector <ll> (200001, 0)}; void add(ll id, ll cur) { while (id <= mp.size()) { if (lazy[id] != cur) { lazy[id] = cur, val[id] = 0; } ++val[id]; id += id&-id; } } ll sum(ll id, ll cur) { ll res = 0; while (id) { if (lazy[id] != cur) { lazy[id] = cur, val[id] = 0; } res += val[id]; id -= id&-id; } return res; } }bit; void cdq(ll id, ll l, ll r) { if (l == r) return; ll mid = (l+r)/2; cdq(id*2, l, mid); cdq(id*2+1, mid+1, r); int i=l, j=mid+1; vector <array<ll, 4>> tmp; while (i <= mid && j <= r) { if (Q[i][1] >= Q[j][1]) { if (Q[i][3] == -1) bit.add(mp.size()-Q[i][2], id); tmp.push_back(Q[i++]); } else { if (Q[j][3] != -1) F[Q[j][3]] += bit.sum(mp.size()-Q[j][2], id); tmp.push_back(Q[j++]); } } while (i <= mid) tmp.push_back(Q[i++]); while (j <= r) { if (Q[j][3] != -1) F[Q[j][3]] += bit.sum(mp.size()-Q[j][2], id); tmp.push_back(Q[j++]); } for (int i=l; i<=r; ++i) swap(Q[i], tmp[i-l]); } int main() { cin >> n >> q; for (int i=0; i<n; ++i) { cin >> a >> b; c = a+b; ++mp[c]; Q.push_back({a, b, c, -1}); } for (int i=0; i<q; ++i) { cin >> a >> b >> c; ++mp[c]; Q.push_back({a, b, c, i}); } sort(Q.begin(), Q.end(), [](auto a, auto b) { return a[0] > b[0] || (a[0] == b[0] && a[3] < b[3]); }); int i=0; for (auto &[x, y] : mp) { y = i++; } for (auto &[a, b, c, d] : Q) { c = mp[c]; } cdq(1, 0, Q.size()-1); for (int i=0; i<q; ++i) cout << F[i] << '\n'; }

Compilation message (stderr)

examination.cpp: In member function 'void BIT::add(long long int, long long int)':
examination.cpp:18:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while (id <= mp.size()) {
      |            ~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...