답안 #559704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559704 2022-05-10T12:42:38 Z SSRS 무지개나라 (APIO17_rainbow) C++14
100 / 100
1364 ms 143788 KB
#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
struct range_tree{
  int N;
  vector<vector<int>> ST;
  range_tree(){
  }
  range_tree(int N2){
    N = 1;
    while (N < N2){
      N *= 2;
    }
    ST = vector<vector<int>>(N * 2 - 1);
  }
  void add(int X, int Y){
    X += N - 1;
    ST[X].push_back(Y);
    while (X > 0){
      X = (X - 1) / 2;
      ST[X].push_back(Y);
    }
  }
  void build(){
    for (int i = 0; i < N * 2 - 1; i++){
      sort(ST[i].begin(), ST[i].end());
    }
  }
  int rectangle_sum(int L, int R, int U, int D, int i, int l, int r){
    if (r <= L || R <= l){
      return 0;
    } else if (L <= l && r <= R){
      return lower_bound(ST[i].begin(), ST[i].end(), D) - lower_bound(ST[i].begin(), ST[i].end(), U);
    } else {
      int m = (l + r) / 2;
      return rectangle_sum(L, R, U, D, i * 2 + 1, l, m) + rectangle_sum(L, R, U, D, i * 2 + 2, m, r);
    }
  }
  int rectangle_sum(int L, int R, int U, int D){
    return rectangle_sum(L, R, U, D, 0, 0, N);
  }
};
int xmin, xmax, ymin, ymax;
range_tree ST1, ST2, ST3, ST4;
void init(int R, int C, int sr, int sc, int M, char *S){
  sr--;
  sc--;
  vector<int> x(M + 1), y(M + 1);
  x[0] = sr;
  y[0] = sc;
  for (int i = 0; i < M; i++){
    x[i + 1] = x[i];
    y[i + 1] = y[i];
    if (S[i] == 'N'){
      x[i + 1]--;
    }
    if (S[i] == 'S'){
      x[i + 1]++;
    }
    if (S[i] == 'E'){
      y[i + 1]++;
    }
    if (S[i] == 'W'){
      y[i + 1]--;
    }
  }
  xmin = sr;
  xmax = sr;
  ymin = sc;
  ymax = sc;
  for (int i = 1; i <= M; i++){
    xmin = min(xmin, x[i]);
    xmax = max(xmax, x[i]);
    ymin = min(ymin, y[i]);
    ymax = max(ymax, y[i]);
  }
  set<pair<int, int>> st1, st2, st3, st4;
  for (int i = 0; i <= M; i++){
    st1.insert(make_pair(x[i], y[i]));
    st2.insert(make_pair(x[i], y[i]));
    st2.insert(make_pair(x[i] - 1, y[i]));
    st3.insert(make_pair(x[i], y[i]));
    st3.insert(make_pair(x[i], y[i] - 1));
    st4.insert(make_pair(x[i], y[i]));
    st4.insert(make_pair(x[i] - 1, y[i]));
    st4.insert(make_pair(x[i], y[i] - 1));
    st4.insert(make_pair(x[i] - 1, y[i] - 1));
  }
  ST1 = range_tree(R + 1);
  for (auto P : st1){
    ST1.add(P.first, P.second);
  }
  ST1.build();
  ST2 = range_tree(R);
  for (auto P : st2){
    if (P.first >= 0){
      ST2.add(P.first, P.second);
    }
  }
  ST2.build();
  ST3 = range_tree(R + 1);
  for (auto P : st3){
    if (P.second >= 0 ){
      ST3.add(P.first, P.second);
    }
  }
  ST3.build();
  ST4 = range_tree(R);
  for (auto P : st4){
    if (P.first >= 0 && P.second >= 0){
      ST4.add(P.first, P.second);
    }
  }
  ST4.build();
}
int colour(int ar, int ac, int br, int bc){
  ar--;
  ac--;
  int ans = 1;
  ans -= ST1.rectangle_sum(ar, br, ac, bc);
  ans += ST2.rectangle_sum(ar, br - 1, ac, bc);
  ans += ST3.rectangle_sum(ar, br, ac, bc - 1);
  ans -= ST4.rectangle_sum(ar, br - 1, ac, bc - 1);
  if (ar < xmin && xmax < br - 1 && ac < ymin && ymax < bc - 1){
    ans++;
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 724 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 436 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 572 KB Output is correct
13 Correct 7 ms 952 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 272 ms 21468 KB Output is correct
4 Correct 364 ms 35504 KB Output is correct
5 Correct 391 ms 35092 KB Output is correct
6 Correct 360 ms 27124 KB Output is correct
7 Correct 373 ms 26544 KB Output is correct
8 Correct 73 ms 1356 KB Output is correct
9 Correct 360 ms 35364 KB Output is correct
10 Correct 397 ms 35120 KB Output is correct
11 Correct 377 ms 27224 KB Output is correct
12 Correct 348 ms 33268 KB Output is correct
13 Correct 367 ms 35508 KB Output is correct
14 Correct 358 ms 35048 KB Output is correct
15 Correct 331 ms 27188 KB Output is correct
16 Correct 301 ms 25148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1027 ms 129692 KB Output is correct
3 Correct 551 ms 140976 KB Output is correct
4 Correct 485 ms 135588 KB Output is correct
5 Correct 515 ms 114920 KB Output is correct
6 Correct 184 ms 65976 KB Output is correct
7 Correct 342 ms 80624 KB Output is correct
8 Correct 291 ms 35336 KB Output is correct
9 Correct 334 ms 33056 KB Output is correct
10 Correct 172 ms 41460 KB Output is correct
11 Correct 376 ms 65452 KB Output is correct
12 Correct 968 ms 129720 KB Output is correct
13 Correct 524 ms 140976 KB Output is correct
14 Correct 489 ms 135780 KB Output is correct
15 Correct 497 ms 114800 KB Output is correct
16 Correct 171 ms 63052 KB Output is correct
17 Correct 329 ms 81412 KB Output is correct
18 Correct 631 ms 131104 KB Output is correct
19 Correct 677 ms 130352 KB Output is correct
20 Correct 676 ms 130148 KB Output is correct
21 Correct 283 ms 35416 KB Output is correct
22 Correct 305 ms 32948 KB Output is correct
23 Correct 177 ms 41620 KB Output is correct
24 Correct 383 ms 65332 KB Output is correct
25 Correct 976 ms 129780 KB Output is correct
26 Correct 534 ms 140972 KB Output is correct
27 Correct 516 ms 135632 KB Output is correct
28 Correct 468 ms 114808 KB Output is correct
29 Correct 173 ms 63108 KB Output is correct
30 Correct 309 ms 81532 KB Output is correct
31 Correct 637 ms 131120 KB Output is correct
32 Correct 676 ms 130296 KB Output is correct
33 Correct 676 ms 130116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 724 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 436 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 572 KB Output is correct
13 Correct 7 ms 952 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1051 ms 31880 KB Output is correct
19 Correct 155 ms 2320 KB Output is correct
20 Correct 146 ms 1352 KB Output is correct
21 Correct 168 ms 1692 KB Output is correct
22 Correct 166 ms 2036 KB Output is correct
23 Correct 148 ms 2324 KB Output is correct
24 Correct 194 ms 1500 KB Output is correct
25 Correct 190 ms 1976 KB Output is correct
26 Correct 209 ms 2128 KB Output is correct
27 Correct 553 ms 26528 KB Output is correct
28 Correct 387 ms 13352 KB Output is correct
29 Correct 499 ms 23936 KB Output is correct
30 Correct 979 ms 60364 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 765 ms 27468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 724 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 436 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 572 KB Output is correct
13 Correct 7 ms 952 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1051 ms 31880 KB Output is correct
19 Correct 155 ms 2320 KB Output is correct
20 Correct 146 ms 1352 KB Output is correct
21 Correct 168 ms 1692 KB Output is correct
22 Correct 166 ms 2036 KB Output is correct
23 Correct 148 ms 2324 KB Output is correct
24 Correct 194 ms 1500 KB Output is correct
25 Correct 190 ms 1976 KB Output is correct
26 Correct 209 ms 2128 KB Output is correct
27 Correct 553 ms 26528 KB Output is correct
28 Correct 387 ms 13352 KB Output is correct
29 Correct 499 ms 23936 KB Output is correct
30 Correct 979 ms 60364 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 765 ms 27468 KB Output is correct
33 Correct 1027 ms 129692 KB Output is correct
34 Correct 551 ms 140976 KB Output is correct
35 Correct 485 ms 135588 KB Output is correct
36 Correct 515 ms 114920 KB Output is correct
37 Correct 184 ms 65976 KB Output is correct
38 Correct 342 ms 80624 KB Output is correct
39 Correct 291 ms 35336 KB Output is correct
40 Correct 334 ms 33056 KB Output is correct
41 Correct 172 ms 41460 KB Output is correct
42 Correct 376 ms 65452 KB Output is correct
43 Correct 968 ms 129720 KB Output is correct
44 Correct 524 ms 140976 KB Output is correct
45 Correct 489 ms 135780 KB Output is correct
46 Correct 497 ms 114800 KB Output is correct
47 Correct 171 ms 63052 KB Output is correct
48 Correct 329 ms 81412 KB Output is correct
49 Correct 631 ms 131104 KB Output is correct
50 Correct 677 ms 130352 KB Output is correct
51 Correct 676 ms 130148 KB Output is correct
52 Correct 283 ms 35416 KB Output is correct
53 Correct 305 ms 32948 KB Output is correct
54 Correct 177 ms 41620 KB Output is correct
55 Correct 383 ms 65332 KB Output is correct
56 Correct 976 ms 129780 KB Output is correct
57 Correct 534 ms 140972 KB Output is correct
58 Correct 516 ms 135632 KB Output is correct
59 Correct 468 ms 114808 KB Output is correct
60 Correct 173 ms 63108 KB Output is correct
61 Correct 309 ms 81532 KB Output is correct
62 Correct 637 ms 131120 KB Output is correct
63 Correct 676 ms 130296 KB Output is correct
64 Correct 676 ms 130116 KB Output is correct
65 Correct 272 ms 21468 KB Output is correct
66 Correct 364 ms 35504 KB Output is correct
67 Correct 391 ms 35092 KB Output is correct
68 Correct 360 ms 27124 KB Output is correct
69 Correct 373 ms 26544 KB Output is correct
70 Correct 73 ms 1356 KB Output is correct
71 Correct 360 ms 35364 KB Output is correct
72 Correct 397 ms 35120 KB Output is correct
73 Correct 377 ms 27224 KB Output is correct
74 Correct 348 ms 33268 KB Output is correct
75 Correct 367 ms 35508 KB Output is correct
76 Correct 358 ms 35048 KB Output is correct
77 Correct 331 ms 27188 KB Output is correct
78 Correct 301 ms 25148 KB Output is correct
79 Correct 486 ms 37568 KB Output is correct
80 Correct 574 ms 35676 KB Output is correct
81 Correct 450 ms 44512 KB Output is correct
82 Correct 708 ms 67980 KB Output is correct
83 Correct 1364 ms 132652 KB Output is correct
84 Correct 1239 ms 143788 KB Output is correct
85 Correct 872 ms 138392 KB Output is correct
86 Correct 940 ms 117596 KB Output is correct
87 Correct 483 ms 65784 KB Output is correct
88 Correct 664 ms 84160 KB Output is correct
89 Correct 946 ms 134016 KB Output is correct
90 Correct 1170 ms 133100 KB Output is correct
91 Correct 1191 ms 132736 KB Output is correct