답안 #126852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126852 2019-07-08T14:06:32 Z Mohammad_Yasser Examination (JOI19_examination) C++14
100 / 100
1807 ms 77980 KB
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;
typedef pair<int, int> pi;

const int N = 1e5 + 5;

map<int, int> mp_x, mp_y;

template<class T> using Tree = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

void compress() {
  int curr = N;
  for (auto& p : mp_x) {
    p.second = --curr;
  }
  curr = N;
  for (auto& p : mp_y) {
    p.second = --curr;
  }
}

template<int SZ> struct mstree {
  Tree<pi> val[SZ + 1]; // for offline queries use vector with binary search instead

  void upd(int x, int y, int t = 1) { // x-coordinate between 1 and SZ inclusive
    for (int X = x; X <= SZ; X += X & -X) {
      if (t == 1)
        val[X].insert( { y, x });
      else
        val[X].erase( { y, x });
    }
  }

  int query(int x, int y) {
    int t = 0;
    for (; x > 0; x -= x & -x)
      t += val[x].order_of_key( { y, N });
    return t;
  }

  int query(int lox, int hix, int loy, int hiy) { // query number of elements within a rectangle
    return query(hix, hiy) - query(lox - 1, hiy) - query(hix, loy - 1)
      + query(lox - 1, loy - 1);
  }
};

mstree<N> bit;

struct Score {
  int x, y;
  int sum;

  bool operator<(const Score& other) const {
    return sum < other.sum;
  }
};

struct Query {
  int x, y, z;
  int ind;
  int res;
  bool operator<(const Query& other) const {
    return z < other.z;
  }
};

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cerr.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, q;
  cin >> n >> q;

  vector<Score> scores(n);
  vector<Query> queries(q);

  for (auto& score : scores) {
    cin >> score.x >> score.y;
    score.sum = score.x + score.y;

    mp_x[score.x];
    mp_y[score.y];
  }
  mp_x[INT_MAX], mp_y[INT_MAX];

  for (int i = 0; i < q; ++i) {
    auto& query = queries[i];
    cin >> query.x >> query.y >> query.z;
    query.ind = i;
  }

  compress();

  for (auto& score : scores) {
    score.x = mp_x[score.x];
    score.y = mp_y[score.y];
  }

  for (auto& query : queries) {
    query.x = mp_x.lower_bound(query.x)->second;
    query.y = mp_y.lower_bound(query.y)->second;
  }

  sort(scores.begin(), scores.end());
  sort(queries.rbegin(), queries.rend());

  for (auto& query : queries) {
    while (!scores.empty() && scores.back().sum >= query.z) {
      bit.upd(scores.back().x, scores.back().y);
      scores.pop_back();
    }
    query.res = bit.query(query.x, query.y);
  }

  sort(queries.begin(), queries.end(), [](const Query& a , const Query& b) {
    return a.ind < b.ind;
  });

  for (auto& query : queries) {
    cout << query.res << endl;
  }

}

Compilation message

examination.cpp:5:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:1024000000,1024000000")
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 9720 KB Output is correct
2 Correct 14 ms 9720 KB Output is correct
3 Correct 14 ms 9720 KB Output is correct
4 Correct 14 ms 9720 KB Output is correct
5 Correct 14 ms 9720 KB Output is correct
6 Correct 14 ms 9720 KB Output is correct
7 Correct 27 ms 11256 KB Output is correct
8 Correct 26 ms 11256 KB Output is correct
9 Correct 27 ms 11256 KB Output is correct
10 Correct 24 ms 11100 KB Output is correct
11 Correct 24 ms 10360 KB Output is correct
12 Correct 18 ms 10232 KB Output is correct
13 Correct 31 ms 11256 KB Output is correct
14 Correct 28 ms 11256 KB Output is correct
15 Correct 27 ms 11228 KB Output is correct
16 Correct 19 ms 10232 KB Output is correct
17 Correct 22 ms 11000 KB Output is correct
18 Correct 17 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1505 ms 71708 KB Output is correct
2 Correct 1551 ms 71672 KB Output is correct
3 Correct 1547 ms 71640 KB Output is correct
4 Correct 1049 ms 68728 KB Output is correct
5 Correct 385 ms 30200 KB Output is correct
6 Correct 255 ms 27256 KB Output is correct
7 Correct 1355 ms 71560 KB Output is correct
8 Correct 1424 ms 71400 KB Output is correct
9 Correct 1188 ms 71672 KB Output is correct
10 Correct 286 ms 22644 KB Output is correct
11 Correct 865 ms 68472 KB Output is correct
12 Correct 171 ms 19448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1505 ms 71708 KB Output is correct
2 Correct 1551 ms 71672 KB Output is correct
3 Correct 1547 ms 71640 KB Output is correct
4 Correct 1049 ms 68728 KB Output is correct
5 Correct 385 ms 30200 KB Output is correct
6 Correct 255 ms 27256 KB Output is correct
7 Correct 1355 ms 71560 KB Output is correct
8 Correct 1424 ms 71400 KB Output is correct
9 Correct 1188 ms 71672 KB Output is correct
10 Correct 286 ms 22644 KB Output is correct
11 Correct 865 ms 68472 KB Output is correct
12 Correct 171 ms 19448 KB Output is correct
13 Correct 1472 ms 71620 KB Output is correct
14 Correct 1566 ms 71516 KB Output is correct
15 Correct 1613 ms 71688 KB Output is correct
16 Correct 870 ms 68652 KB Output is correct
17 Correct 385 ms 30072 KB Output is correct
18 Correct 257 ms 27256 KB Output is correct
19 Correct 1442 ms 71680 KB Output is correct
20 Correct 1535 ms 71672 KB Output is correct
21 Correct 1274 ms 71544 KB Output is correct
22 Correct 300 ms 22648 KB Output is correct
23 Correct 779 ms 68600 KB Output is correct
24 Correct 157 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 9720 KB Output is correct
2 Correct 14 ms 9720 KB Output is correct
3 Correct 14 ms 9720 KB Output is correct
4 Correct 14 ms 9720 KB Output is correct
5 Correct 14 ms 9720 KB Output is correct
6 Correct 14 ms 9720 KB Output is correct
7 Correct 27 ms 11256 KB Output is correct
8 Correct 26 ms 11256 KB Output is correct
9 Correct 27 ms 11256 KB Output is correct
10 Correct 24 ms 11100 KB Output is correct
11 Correct 24 ms 10360 KB Output is correct
12 Correct 18 ms 10232 KB Output is correct
13 Correct 31 ms 11256 KB Output is correct
14 Correct 28 ms 11256 KB Output is correct
15 Correct 27 ms 11228 KB Output is correct
16 Correct 19 ms 10232 KB Output is correct
17 Correct 22 ms 11000 KB Output is correct
18 Correct 17 ms 9976 KB Output is correct
19 Correct 1505 ms 71708 KB Output is correct
20 Correct 1551 ms 71672 KB Output is correct
21 Correct 1547 ms 71640 KB Output is correct
22 Correct 1049 ms 68728 KB Output is correct
23 Correct 385 ms 30200 KB Output is correct
24 Correct 255 ms 27256 KB Output is correct
25 Correct 1355 ms 71560 KB Output is correct
26 Correct 1424 ms 71400 KB Output is correct
27 Correct 1188 ms 71672 KB Output is correct
28 Correct 286 ms 22644 KB Output is correct
29 Correct 865 ms 68472 KB Output is correct
30 Correct 171 ms 19448 KB Output is correct
31 Correct 1472 ms 71620 KB Output is correct
32 Correct 1566 ms 71516 KB Output is correct
33 Correct 1613 ms 71688 KB Output is correct
34 Correct 870 ms 68652 KB Output is correct
35 Correct 385 ms 30072 KB Output is correct
36 Correct 257 ms 27256 KB Output is correct
37 Correct 1442 ms 71680 KB Output is correct
38 Correct 1535 ms 71672 KB Output is correct
39 Correct 1274 ms 71544 KB Output is correct
40 Correct 300 ms 22648 KB Output is correct
41 Correct 779 ms 68600 KB Output is correct
42 Correct 157 ms 19320 KB Output is correct
43 Correct 1615 ms 77904 KB Output is correct
44 Correct 1582 ms 77904 KB Output is correct
45 Correct 1807 ms 77904 KB Output is correct
46 Correct 914 ms 73208 KB Output is correct
47 Correct 433 ms 31892 KB Output is correct
48 Correct 221 ms 26844 KB Output is correct
49 Correct 1473 ms 77812 KB Output is correct
50 Correct 1391 ms 77904 KB Output is correct
51 Correct 1290 ms 77980 KB Output is correct
52 Correct 323 ms 24312 KB Output is correct
53 Correct 829 ms 72980 KB Output is correct