Submission #960403

# Submission time Handle Problem Language Result Execution time Memory
960403 2024-04-10T11:52:43 Z abczz Examination (JOI19_examination) C++14
0 / 100
292 ms 30256 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];
  });
  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()) {
      |            ~~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |   for (auto &[x, y] : mp) {
      |              ^
examination.cpp:84:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |   for (auto &[a, b, c, d] : Q) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 1 ms 3592 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 12 ms 4568 KB Output is correct
8 Correct 11 ms 4568 KB Output is correct
9 Correct 11 ms 4568 KB Output is correct
10 Correct 9 ms 4564 KB Output is correct
11 Incorrect 10 ms 4512 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 30256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 30256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 1 ms 3592 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 12 ms 4568 KB Output is correct
8 Correct 11 ms 4568 KB Output is correct
9 Correct 11 ms 4568 KB Output is correct
10 Correct 9 ms 4564 KB Output is correct
11 Incorrect 10 ms 4512 KB Output isn't correct
12 Halted 0 ms 0 KB -