Submission #166350

# Submission time Handle Problem Language Result Execution time Memory
166350 2019-12-01T16:37:33 Z combi1k1 Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
1315 ms 80932 KB
#include "rainbow.h"
#include<bits/stdc++.h>

using namespace std;

#define X   first
#define Y   second

#define pb  emplace_back

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

const int   N   = 2e5 + 1;

typedef pair<int,int>   ii;
typedef vector<int>     vi;

vector<vi>  dx = {{0},{0,1},{0},{0,1}};
vector<vi>  dy = {{0},{0,1},{0,1},{0}};

struct  BIT2D   {
    vector<ii>  add;
    vector<int> v[N];
    void ini()  {
        sort(add.begin(),add.end());
        add.erase(unique(add.begin(),add.end()),add.end());
        for(ii  a : add)
        for(int x = a.X ; x < N ; x += x & -x)
            v[x].push_back(a.Y);
        for(int i = 1 ; i < N ; ++i)
            sort(v[i].begin(),v[i].end());
    }
    int get(int x,int l,int r)  {
        int ans = 0;
        for(; x > 0 ; x -= x & -x)  {
            auto L = lower_bound(v[x].begin(),v[x].end(),l);
            auto R = upper_bound(v[x].begin(),v[x].end(),r);

            ans += R - L;
        }
        return  ans;
    }
    int get(int l,int r,int u,int d)    {
        if (l > r)  return  0;
        if (u > d)  return  0;

        return  get(r,u,d) - get(l - 1,u,d);
    }
}   T[4];

int min_r =  1e9, min_c =  1e9;
int max_r = -1e9, max_c = -1e9;

void rose(ii  P)    {
    min_r = min(min_r,P.X); max_r = max(max_r,P.X);
    min_c = min(min_c,P.Y); max_c = max(max_c,P.Y);

    for(int i = 0 ; i < 4 ; ++i)
    for(int x : dx[i])
    for(int y : dy[i])  T[i].add.pb(P.X + x,P.Y + y);
}
void init(int R,int C,int sr,int sc,int m,char *S)  {
    ii  Head(sr,sc);    rose(Head);

    for(int i = 0 ; i < m ; ++i)    {
        char c = S[i];
        if (c == 'N')   Head.X--;
        if (c == 'S')   Head.X++;
        if (c == 'W')   Head.Y--;
        if (c == 'E')   Head.Y++;

        rose(Head);
    }
    for(int i = 0 ; i < 4 ; ++i)    T[i].ini();
}
int colour(int l,int u,int r,int d) {
    int V = T[1].get(l + 1,r,u + 1,d);
    int F = T[0].get(l,r,u,d);
    int E = T[2].get(l,r,u + 1,d) + T[3].get(l + 1,r,u,d);

    return  E - V - F + 1 + (l < min_r && max_r < r && u < min_c && max_c < d);
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 29 ms 19704 KB Output is correct
3 Correct 25 ms 19320 KB Output is correct
4 Correct 26 ms 19448 KB Output is correct
5 Correct 31 ms 19836 KB Output is correct
6 Correct 21 ms 19204 KB Output is correct
7 Correct 22 ms 19192 KB Output is correct
8 Correct 21 ms 19192 KB Output is correct
9 Correct 21 ms 19064 KB Output is correct
10 Correct 28 ms 19192 KB Output is correct
11 Correct 26 ms 19448 KB Output is correct
12 Correct 28 ms 19576 KB Output is correct
13 Correct 31 ms 19960 KB Output is correct
14 Correct 34 ms 20344 KB Output is correct
15 Correct 21 ms 19064 KB Output is correct
16 Correct 21 ms 19064 KB Output is correct
17 Correct 22 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 19064 KB Output is correct
2 Correct 22 ms 19192 KB Output is correct
3 Correct 608 ms 53704 KB Output is correct
4 Correct 943 ms 80844 KB Output is correct
5 Correct 961 ms 80584 KB Output is correct
6 Correct 790 ms 75200 KB Output is correct
7 Correct 761 ms 70356 KB Output is correct
8 Correct 143 ms 31580 KB Output is correct
9 Correct 839 ms 80932 KB Output is correct
10 Correct 914 ms 80732 KB Output is correct
11 Correct 770 ms 75356 KB Output is correct
12 Correct 1025 ms 78400 KB Output is correct
13 Correct 789 ms 80728 KB Output is correct
14 Correct 778 ms 80604 KB Output is correct
15 Correct 694 ms 75104 KB Output is correct
16 Correct 736 ms 72260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 19064 KB Output is correct
2 Correct 469 ms 53420 KB Output is correct
3 Correct 239 ms 57496 KB Output is correct
4 Correct 258 ms 57640 KB Output is correct
5 Correct 250 ms 48320 KB Output is correct
6 Correct 153 ms 32476 KB Output is correct
7 Correct 223 ms 35396 KB Output is correct
8 Correct 638 ms 72200 KB Output is correct
9 Correct 554 ms 68816 KB Output is correct
10 Correct 127 ms 29012 KB Output is correct
11 Correct 253 ms 41920 KB Output is correct
12 Correct 473 ms 53336 KB Output is correct
13 Correct 225 ms 57564 KB Output is correct
14 Correct 246 ms 57692 KB Output is correct
15 Correct 247 ms 48320 KB Output is correct
16 Correct 157 ms 31580 KB Output is correct
17 Correct 226 ms 39140 KB Output is correct
18 Correct 496 ms 67420 KB Output is correct
19 Correct 355 ms 56772 KB Output is correct
20 Correct 433 ms 60892 KB Output is correct
21 Correct 583 ms 72412 KB Output is correct
22 Correct 542 ms 68832 KB Output is correct
23 Correct 128 ms 29032 KB Output is correct
24 Correct 252 ms 41972 KB Output is correct
25 Correct 486 ms 53408 KB Output is correct
26 Correct 237 ms 57728 KB Output is correct
27 Correct 234 ms 57692 KB Output is correct
28 Correct 263 ms 48432 KB Output is correct
29 Correct 293 ms 31584 KB Output is correct
30 Correct 230 ms 39132 KB Output is correct
31 Correct 499 ms 67376 KB Output is correct
32 Correct 378 ms 56852 KB Output is correct
33 Correct 401 ms 60764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 29 ms 19704 KB Output is correct
3 Correct 25 ms 19320 KB Output is correct
4 Correct 26 ms 19448 KB Output is correct
5 Correct 31 ms 19836 KB Output is correct
6 Correct 21 ms 19204 KB Output is correct
7 Correct 22 ms 19192 KB Output is correct
8 Correct 21 ms 19192 KB Output is correct
9 Correct 21 ms 19064 KB Output is correct
10 Correct 28 ms 19192 KB Output is correct
11 Correct 26 ms 19448 KB Output is correct
12 Correct 28 ms 19576 KB Output is correct
13 Correct 31 ms 19960 KB Output is correct
14 Correct 34 ms 20344 KB Output is correct
15 Correct 21 ms 19064 KB Output is correct
16 Correct 21 ms 19064 KB Output is correct
17 Correct 22 ms 19192 KB Output is correct
18 Correct 1315 ms 49168 KB Output is correct
19 Correct 341 ms 24184 KB Output is correct
20 Correct 255 ms 22912 KB Output is correct
21 Correct 283 ms 23032 KB Output is correct
22 Correct 319 ms 23420 KB Output is correct
23 Correct 321 ms 24088 KB Output is correct
24 Correct 306 ms 23288 KB Output is correct
25 Correct 340 ms 23424 KB Output is correct
26 Correct 341 ms 23672 KB Output is correct
27 Correct 585 ms 45404 KB Output is correct
28 Correct 485 ms 37724 KB Output is correct
29 Correct 525 ms 43100 KB Output is correct
30 Correct 1117 ms 70808 KB Output is correct
31 Correct 25 ms 19320 KB Output is correct
32 Correct 948 ms 48220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 29 ms 19704 KB Output is correct
3 Correct 25 ms 19320 KB Output is correct
4 Correct 26 ms 19448 KB Output is correct
5 Correct 31 ms 19836 KB Output is correct
6 Correct 21 ms 19204 KB Output is correct
7 Correct 22 ms 19192 KB Output is correct
8 Correct 21 ms 19192 KB Output is correct
9 Correct 21 ms 19064 KB Output is correct
10 Correct 28 ms 19192 KB Output is correct
11 Correct 26 ms 19448 KB Output is correct
12 Correct 28 ms 19576 KB Output is correct
13 Correct 31 ms 19960 KB Output is correct
14 Correct 34 ms 20344 KB Output is correct
15 Correct 21 ms 19064 KB Output is correct
16 Correct 21 ms 19064 KB Output is correct
17 Correct 22 ms 19192 KB Output is correct
18 Correct 1315 ms 49168 KB Output is correct
19 Correct 341 ms 24184 KB Output is correct
20 Correct 255 ms 22912 KB Output is correct
21 Correct 283 ms 23032 KB Output is correct
22 Correct 319 ms 23420 KB Output is correct
23 Correct 321 ms 24088 KB Output is correct
24 Correct 306 ms 23288 KB Output is correct
25 Correct 340 ms 23424 KB Output is correct
26 Correct 341 ms 23672 KB Output is correct
27 Correct 585 ms 45404 KB Output is correct
28 Correct 485 ms 37724 KB Output is correct
29 Correct 525 ms 43100 KB Output is correct
30 Correct 1117 ms 70808 KB Output is correct
31 Correct 25 ms 19320 KB Output is correct
32 Correct 948 ms 48220 KB Output is correct
33 Correct 469 ms 53420 KB Output is correct
34 Correct 239 ms 57496 KB Output is correct
35 Correct 258 ms 57640 KB Output is correct
36 Correct 250 ms 48320 KB Output is correct
37 Correct 153 ms 32476 KB Output is correct
38 Correct 223 ms 35396 KB Output is correct
39 Correct 638 ms 72200 KB Output is correct
40 Correct 554 ms 68816 KB Output is correct
41 Correct 127 ms 29012 KB Output is correct
42 Correct 253 ms 41920 KB Output is correct
43 Correct 473 ms 53336 KB Output is correct
44 Correct 225 ms 57564 KB Output is correct
45 Correct 246 ms 57692 KB Output is correct
46 Correct 247 ms 48320 KB Output is correct
47 Correct 157 ms 31580 KB Output is correct
48 Correct 226 ms 39140 KB Output is correct
49 Correct 496 ms 67420 KB Output is correct
50 Correct 355 ms 56772 KB Output is correct
51 Correct 433 ms 60892 KB Output is correct
52 Correct 583 ms 72412 KB Output is correct
53 Correct 542 ms 68832 KB Output is correct
54 Correct 128 ms 29032 KB Output is correct
55 Correct 252 ms 41972 KB Output is correct
56 Correct 486 ms 53408 KB Output is correct
57 Correct 237 ms 57728 KB Output is correct
58 Correct 234 ms 57692 KB Output is correct
59 Correct 263 ms 48432 KB Output is correct
60 Correct 293 ms 31584 KB Output is correct
61 Correct 230 ms 39132 KB Output is correct
62 Correct 499 ms 67376 KB Output is correct
63 Correct 378 ms 56852 KB Output is correct
64 Correct 401 ms 60764 KB Output is correct
65 Correct 1008 ms 75856 KB Output is correct
66 Correct 1054 ms 72540 KB Output is correct
67 Correct 473 ms 32564 KB Output is correct
68 Correct 679 ms 45444 KB Output is correct
69 Correct 823 ms 57068 KB Output is correct
70 Correct 817 ms 61164 KB Output is correct
71 Correct 654 ms 61276 KB Output is correct
72 Correct 676 ms 51960 KB Output is correct
73 Correct 361 ms 35136 KB Output is correct
74 Correct 469 ms 42688 KB Output is correct
75 Correct 753 ms 70840 KB Output is correct
76 Correct 859 ms 60380 KB Output is correct
77 Correct 725 ms 64448 KB Output is correct
78 Correct 608 ms 53704 KB Output is correct
79 Correct 943 ms 80844 KB Output is correct
80 Correct 961 ms 80584 KB Output is correct
81 Correct 790 ms 75200 KB Output is correct
82 Correct 761 ms 70356 KB Output is correct
83 Correct 143 ms 31580 KB Output is correct
84 Correct 839 ms 80932 KB Output is correct
85 Correct 914 ms 80732 KB Output is correct
86 Correct 770 ms 75356 KB Output is correct
87 Correct 1025 ms 78400 KB Output is correct
88 Correct 789 ms 80728 KB Output is correct
89 Correct 778 ms 80604 KB Output is correct
90 Correct 694 ms 75104 KB Output is correct
91 Correct 736 ms 72260 KB Output is correct