Submission #261223

# Submission time Handle Problem Language Result Execution time Memory
261223 2020-08-11T14:53:41 Z Bruteforceman Examination (JOI19_examination) C++11
100 / 100
580 ms 15808 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
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];
int n, idx;
int ans[maxn];
int t[maxn];
void update(int x, int val) {
  for(int i = x; i <= idx; i += i & (-i)) t[i] += val;
}
int query(int x) {
  int sum = 0;
  for(int i = x; i > 0; i -= i & (-i)) {
    sum += t[i];
  }
  return sum;
}
void solve(int l, int r) {
  if(l == r) return ;
  int m = (l + r) >> 1;
  solve(l, m);
  solve(m + 1, r);
  vector <int> cont;
  for(int i = l; i <= m; i++) {
    if(a[i].id <= n) cont.emplace_back(i);
  }
  for(int i = m + 1; i <= r; i++) {
    if(a[i].id > n) cont.emplace_back(i);
  }
  sort(cont.begin(), cont.end(), 
    [&] (int i, int j) {
      if(a[i].y == a[j].y) return i < j;
      else return a[i].y > a[j].y; 
    }
  );
  for(auto i : cont) {
    if(a[i].id <= n) {
      update(a[i].x, 1);
    } else {
      ans[a[i].id] += query(idx) - query(a[i].x - 1);
    } 
  }
  for(auto i : cont) {
    if(a[i].id <= n) {
      update(a[i].x, -1);
    }
  }
}
 
int main() {
  int 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)];  
    }
  } 
  solve(1, n + q);
  for(int i = 1; i <= q; i++) printf("%d\n", ans[i + n]);
  return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:63: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:69: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:76: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);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 11 ms 768 KB Output is correct
10 Correct 12 ms 768 KB Output is correct
11 Correct 8 ms 512 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 10 ms 768 KB Output is correct
14 Correct 10 ms 768 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 10 ms 768 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 9440 KB Output is correct
2 Correct 452 ms 11124 KB Output is correct
3 Correct 485 ms 11276 KB Output is correct
4 Correct 445 ms 10340 KB Output is correct
5 Correct 283 ms 7232 KB Output is correct
6 Correct 332 ms 6368 KB Output is correct
7 Correct 456 ms 11092 KB Output is correct
8 Correct 466 ms 11100 KB Output is correct
9 Correct 426 ms 11004 KB Output is correct
10 Correct 264 ms 7260 KB Output is correct
11 Correct 377 ms 10336 KB Output is correct
12 Correct 213 ms 6496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 9440 KB Output is correct
2 Correct 452 ms 11124 KB Output is correct
3 Correct 485 ms 11276 KB Output is correct
4 Correct 445 ms 10340 KB Output is correct
5 Correct 283 ms 7232 KB Output is correct
6 Correct 332 ms 6368 KB Output is correct
7 Correct 456 ms 11092 KB Output is correct
8 Correct 466 ms 11100 KB Output is correct
9 Correct 426 ms 11004 KB Output is correct
10 Correct 264 ms 7260 KB Output is correct
11 Correct 377 ms 10336 KB Output is correct
12 Correct 213 ms 6496 KB Output is correct
13 Correct 483 ms 11224 KB Output is correct
14 Correct 505 ms 11896 KB Output is correct
15 Correct 461 ms 11104 KB Output is correct
16 Correct 457 ms 10336 KB Output is correct
17 Correct 308 ms 7176 KB Output is correct
18 Correct 295 ms 6816 KB Output is correct
19 Correct 512 ms 11184 KB Output is correct
20 Correct 580 ms 11180 KB Output is correct
21 Correct 495 ms 11204 KB Output is correct
22 Correct 263 ms 7140 KB Output is correct
23 Correct 347 ms 10336 KB Output is correct
24 Correct 221 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 11 ms 768 KB Output is correct
10 Correct 12 ms 768 KB Output is correct
11 Correct 8 ms 512 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 10 ms 768 KB Output is correct
14 Correct 10 ms 768 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 10 ms 768 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 450 ms 9440 KB Output is correct
20 Correct 452 ms 11124 KB Output is correct
21 Correct 485 ms 11276 KB Output is correct
22 Correct 445 ms 10340 KB Output is correct
23 Correct 283 ms 7232 KB Output is correct
24 Correct 332 ms 6368 KB Output is correct
25 Correct 456 ms 11092 KB Output is correct
26 Correct 466 ms 11100 KB Output is correct
27 Correct 426 ms 11004 KB Output is correct
28 Correct 264 ms 7260 KB Output is correct
29 Correct 377 ms 10336 KB Output is correct
30 Correct 213 ms 6496 KB Output is correct
31 Correct 483 ms 11224 KB Output is correct
32 Correct 505 ms 11896 KB Output is correct
33 Correct 461 ms 11104 KB Output is correct
34 Correct 457 ms 10336 KB Output is correct
35 Correct 308 ms 7176 KB Output is correct
36 Correct 295 ms 6816 KB Output is correct
37 Correct 512 ms 11184 KB Output is correct
38 Correct 580 ms 11180 KB Output is correct
39 Correct 495 ms 11204 KB Output is correct
40 Correct 263 ms 7140 KB Output is correct
41 Correct 347 ms 10336 KB Output is correct
42 Correct 221 ms 6520 KB Output is correct
43 Correct 550 ms 14940 KB Output is correct
44 Correct 534 ms 14948 KB Output is correct
45 Correct 554 ms 15808 KB Output is correct
46 Correct 504 ms 13672 KB Output is correct
47 Correct 311 ms 8288 KB Output is correct
48 Correct 273 ms 5936 KB Output is correct
49 Correct 518 ms 15616 KB Output is correct
50 Correct 532 ms 14876 KB Output is correct
51 Correct 498 ms 15556 KB Output is correct
52 Correct 305 ms 8288 KB Output is correct
53 Correct 467 ms 13280 KB Output is correct