답안 #261205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261205 2020-08-11T14:27:36 Z Bruteforceman Examination (JOI19_examination) C++11
2 / 100
96 ms 42988 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const int maxn = 1e5 + 10;
typedef pair <int, int> pii;
typedef tree <pii,
              null_type,
              less <pii>,
              rb_tree_tag,
              tree_order_statistics_node_update> orderset;
struct info {
  int x, y, z;
  int id;
  info (int x, int y, int z) : x(x), y(y), z(z) {}
  info () {}
  bool operator < (info d) const {
    if(z == d.z) {
      return id < d.id;
    } 
    return z > d.z;
  }
} a[maxn];

orderset t[maxn * 4];
int ans[maxn];
int idx;
void add(int x, int y, int id, int c = 1, int b = 1, int e = idx) {
  t[c].insert(pii(y, id));
  if(b == e) return ;
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if(x <= m) add(x, y, id, l, b, m);
  else add(x, y, id, r, m + 1, e);
}
int query(int x, int y, int val, int c = 1, int b = 1, int e = idx) {
  if(x <= b && e <= y) {
    return t[c].size() - t[c].order_of_key(pii(val, -1));
  }
  if(y < b || e < x) return 0;
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  return query(x, y, val, l, b, m) + query(x, y, val, r, m + 1, e);
}

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  map <int, int> cmp;
  vector <int> v;
  cmp[INT_MAX];
  v.push_back(INT_MAX);
  for(int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].x, &a[i].y);
    a[i].z = a[i].x + a[i].y;
    a[i].id = i;
    cmp[a[i].x];
    v.push_back(a[i].x);
  }
  for(int i = n + 1; i <= n + q; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].z);
    a[i].id = i;
  }
  sort(a + 1, a + n + q + 1);
  idx = 0;
  for(auto &i : cmp) {
    i.second = ++idx;
  }
  sort(v.begin(), v.end());
  for(int i = 1; i <= n + q; i++) {
    if(a[i].id <= n) {
      a[i].x = cmp[a[i].x]; 
    } else {
      a[i].x = cmp[*lower_bound(v.begin(), v.end(), a[i].x)];  
    }
  }
  for(int i = 1; i <= n + q; i++) {
    if(a[i].id > n) {
      ans[a[i].id - n] = query(a[i].x, idx, a[i].y);
    } else {
      add(a[i].x, a[i].y, a[i].id);
    }
  }
  for(int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &a[i].x, &a[i].y);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].z);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 37880 KB Output is correct
2 Correct 45 ms 37880 KB Output is correct
3 Correct 39 ms 37888 KB Output is correct
4 Correct 36 ms 37888 KB Output is correct
5 Correct 39 ms 37888 KB Output is correct
6 Correct 39 ms 37880 KB Output is correct
7 Correct 56 ms 40696 KB Output is correct
8 Correct 54 ms 40696 KB Output is correct
9 Correct 67 ms 40696 KB Output is correct
10 Correct 54 ms 40696 KB Output is correct
11 Correct 56 ms 39032 KB Output is correct
12 Correct 43 ms 38904 KB Output is correct
13 Correct 59 ms 40688 KB Output is correct
14 Correct 66 ms 40696 KB Output is correct
15 Correct 56 ms 40704 KB Output is correct
16 Correct 41 ms 38520 KB Output is correct
17 Correct 55 ms 40672 KB Output is correct
18 Correct 44 ms 38392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 96 ms 42988 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 96 ms 42988 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 37880 KB Output is correct
2 Correct 45 ms 37880 KB Output is correct
3 Correct 39 ms 37888 KB Output is correct
4 Correct 36 ms 37888 KB Output is correct
5 Correct 39 ms 37888 KB Output is correct
6 Correct 39 ms 37880 KB Output is correct
7 Correct 56 ms 40696 KB Output is correct
8 Correct 54 ms 40696 KB Output is correct
9 Correct 67 ms 40696 KB Output is correct
10 Correct 54 ms 40696 KB Output is correct
11 Correct 56 ms 39032 KB Output is correct
12 Correct 43 ms 38904 KB Output is correct
13 Correct 59 ms 40688 KB Output is correct
14 Correct 66 ms 40696 KB Output is correct
15 Correct 56 ms 40704 KB Output is correct
16 Correct 41 ms 38520 KB Output is correct
17 Correct 55 ms 40672 KB Output is correct
18 Correct 44 ms 38392 KB Output is correct
19 Execution timed out 96 ms 42988 KB Time limit exceeded (wall clock)
20 Halted 0 ms 0 KB -