Submission #997871

# Submission time Handle Problem Language Result Execution time Memory
997871 2024-06-13T04:09:55 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
441 ms 39224 KB
#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

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 time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3536 KB Output is correct
7 Correct 10 ms 4568 KB Output is correct
8 Correct 10 ms 4568 KB Output is correct
9 Correct 10 ms 4568 KB Output is correct
10 Correct 8 ms 4568 KB Output is correct
11 Correct 9 ms 4568 KB Output is correct
12 Correct 5 ms 4372 KB Output is correct
13 Correct 8 ms 4256 KB Output is correct
14 Correct 8 ms 4260 KB Output is correct
15 Correct 8 ms 4256 KB Output is correct
16 Correct 7 ms 4384 KB Output is correct
17 Correct 9 ms 4372 KB Output is correct
18 Correct 5 ms 4120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 28724 KB Output is correct
2 Correct 281 ms 29272 KB Output is correct
3 Correct 285 ms 29240 KB Output is correct
4 Correct 235 ms 29144 KB Output is correct
5 Correct 242 ms 28676 KB Output is correct
6 Correct 152 ms 25940 KB Output is correct
7 Correct 282 ms 28612 KB Output is correct
8 Correct 279 ms 28360 KB Output is correct
9 Correct 302 ms 30260 KB Output is correct
10 Correct 245 ms 27336 KB Output is correct
11 Correct 233 ms 28780 KB Output is correct
12 Correct 129 ms 23824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 28724 KB Output is correct
2 Correct 281 ms 29272 KB Output is correct
3 Correct 285 ms 29240 KB Output is correct
4 Correct 235 ms 29144 KB Output is correct
5 Correct 242 ms 28676 KB Output is correct
6 Correct 152 ms 25940 KB Output is correct
7 Correct 282 ms 28612 KB Output is correct
8 Correct 279 ms 28360 KB Output is correct
9 Correct 302 ms 30260 KB Output is correct
10 Correct 245 ms 27336 KB Output is correct
11 Correct 233 ms 28780 KB Output is correct
12 Correct 129 ms 23824 KB Output is correct
13 Correct 369 ms 32372 KB Output is correct
14 Correct 352 ms 30300 KB Output is correct
15 Correct 285 ms 31292 KB Output is correct
16 Correct 305 ms 31968 KB Output is correct
17 Correct 310 ms 30924 KB Output is correct
18 Correct 155 ms 23864 KB Output is correct
19 Correct 353 ms 33940 KB Output is correct
20 Correct 383 ms 33816 KB Output is correct
21 Correct 338 ms 30808 KB Output is correct
22 Correct 237 ms 27960 KB Output is correct
23 Correct 228 ms 29116 KB Output is correct
24 Correct 124 ms 23632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3536 KB Output is correct
7 Correct 10 ms 4568 KB Output is correct
8 Correct 10 ms 4568 KB Output is correct
9 Correct 10 ms 4568 KB Output is correct
10 Correct 8 ms 4568 KB Output is correct
11 Correct 9 ms 4568 KB Output is correct
12 Correct 5 ms 4372 KB Output is correct
13 Correct 8 ms 4256 KB Output is correct
14 Correct 8 ms 4260 KB Output is correct
15 Correct 8 ms 4256 KB Output is correct
16 Correct 7 ms 4384 KB Output is correct
17 Correct 9 ms 4372 KB Output is correct
18 Correct 5 ms 4120 KB Output is correct
19 Correct 282 ms 28724 KB Output is correct
20 Correct 281 ms 29272 KB Output is correct
21 Correct 285 ms 29240 KB Output is correct
22 Correct 235 ms 29144 KB Output is correct
23 Correct 242 ms 28676 KB Output is correct
24 Correct 152 ms 25940 KB Output is correct
25 Correct 282 ms 28612 KB Output is correct
26 Correct 279 ms 28360 KB Output is correct
27 Correct 302 ms 30260 KB Output is correct
28 Correct 245 ms 27336 KB Output is correct
29 Correct 233 ms 28780 KB Output is correct
30 Correct 129 ms 23824 KB Output is correct
31 Correct 369 ms 32372 KB Output is correct
32 Correct 352 ms 30300 KB Output is correct
33 Correct 285 ms 31292 KB Output is correct
34 Correct 305 ms 31968 KB Output is correct
35 Correct 310 ms 30924 KB Output is correct
36 Correct 155 ms 23864 KB Output is correct
37 Correct 353 ms 33940 KB Output is correct
38 Correct 383 ms 33816 KB Output is correct
39 Correct 338 ms 30808 KB Output is correct
40 Correct 237 ms 27960 KB Output is correct
41 Correct 228 ms 29116 KB Output is correct
42 Correct 124 ms 23632 KB Output is correct
43 Correct 423 ms 35904 KB Output is correct
44 Correct 413 ms 38196 KB Output is correct
45 Correct 441 ms 36304 KB Output is correct
46 Correct 371 ms 39224 KB Output is correct
47 Correct 393 ms 37680 KB Output is correct
48 Correct 158 ms 25932 KB Output is correct
49 Correct 424 ms 37176 KB Output is correct
50 Correct 424 ms 38984 KB Output is correct
51 Correct 419 ms 38708 KB Output is correct
52 Correct 392 ms 35592 KB Output is correct
53 Correct 243 ms 30776 KB Output is correct