Submission #969981

# Submission time Handle Problem Language Result Execution time Memory
969981 2024-04-26T03:02:28 Z socpite Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
984 ms 140288 KB
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;

vector<int> pos[4][maxn];
vector<int> FW[4][maxn];

vector<pair<int, int>> E[4];

int r, c;

void fadd(int x, int y, int id){
    for(x; x <= r; x += x&(-x))pos[id][x].push_back(y);
}

void add(int x, int y, int id){
    for(x; x <= r; x += x&(-x)){
        for(int idx = lower_bound(pos[id][x].begin(), pos[id][x].end(), y) - pos[id][x].begin(); idx < FW[id][x].size(); idx += idx&(-idx)){
            FW[id][x][idx]++;
        }
    }
}

int query(int x, int y, int id){
    int re = 0;
    for(x; x > 0; x -= x&(-x)){
        for(int idx = upper_bound(pos[id][x].begin(), pos[id][x].end(), y) - pos[id][x].begin() - 1; idx > 0; idx -= idx&(-idx)){
            re += FW[id][x][idx];
        }
    }
    return re;
}

int query_rect(int x1, int y1, int x2, int y2, int id){
    if(x1 > x2 || y1 > y2)return 0;
    return query(x2, y2, id) - query(x1-1, y2, id) - query(x2, y1-1, id) + query(x1-1, y1-1, id);
}

void add_square(int sr, int sc){
    // cout << sr << " " << sc << endl;
    E[0].push_back({sr, sc});
    E[0].push_back({sr+1, sc});

    E[1].push_back({sr, sc});
    E[1].push_back({sr, sc+1});

    E[2].push_back({sr, sc});

    E[3].push_back({sr, sc});
    E[3].push_back({sr, sc+1});
    E[3].push_back({sr+1, sc+1});
    E[3].push_back({sr+1, sc});
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    r = R;
    c = C;
    add_square(sr, sc);
    for(int i = 0; i < M; i++){
        if(S[i] == 'N')sr--;
        else if(S[i] == 'W')sc--;
        else if(S[i] == 'S')sr++;
        else sc++;
        add_square(sr, sc);
    }
    for(int id = 0; id < 4; id++){
        sort(E[id].begin(), E[id].end());
        E[id].erase(unique(E[id].begin(), E[id].end()), E[id].end());
        for(auto v: E[id])fadd(v.first, v.second, id);

        for(int i = 1; i <= r; i++){
            pos[id][i].push_back(-1);
            sort(pos[id][i].begin(), pos[id][i].end());
            pos[id][i].erase(unique(pos[id][i].begin(), pos[id][i].end()), pos[id][i].end());
            FW[id][i].assign(pos[id][i].size(), 0);
        }

        for(auto v: E[id])add(v.first, v.second, id);                                     
    }
    
}

// V - E + F - C = 1 => F = 1 + C + E - V
// 

int colour(int ar, int ac, int br, int bc) {
    int F = query_rect(ar, ac, br, bc, 2);
    if(F == 0)return 1;
    int V = (br - ar + 1)*2 + (bc - ac + 1)*2 + query_rect(ar+1, ac+1, br, bc, 3);
    int E = (br - ar + 1)*2 + (bc - ac + 1)*2 + query_rect(ar+1, ac, br, bc, 0) + query_rect(ar, ac+1, br, bc, 1);
    int C = 1 + (query_rect(ar+1, ac+1, br-1, bc-1, 2) == F);
    F++;
    return 1 + C + E - V - F;
}

Compilation message

rainbow.cpp: In function 'void fadd(int, int, int)':
rainbow.cpp:15:9: warning: statement has no effect [-Wunused-value]
   15 |     for(x; x <= r; x += x&(-x))pos[id][x].push_back(y);
      |         ^
rainbow.cpp: In function 'void add(int, int, int)':
rainbow.cpp:19:9: warning: statement has no effect [-Wunused-value]
   19 |     for(x; x <= r; x += x&(-x)){
      |         ^
rainbow.cpp:20:102: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for(int idx = lower_bound(pos[id][x].begin(), pos[id][x].end(), y) - pos[id][x].begin(); idx < FW[id][x].size(); idx += idx&(-idx)){
      |                                                                                                  ~~~~^~~~~~~~~~~~~~~~~~
rainbow.cpp: In function 'int query(int, int, int)':
rainbow.cpp:28:9: warning: statement has no effect [-Wunused-value]
   28 |     for(x; x > 0; x -= x&(-x)){
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37980 KB Output is correct
2 Correct 13 ms 38236 KB Output is correct
3 Correct 15 ms 37976 KB Output is correct
4 Correct 13 ms 37980 KB Output is correct
5 Correct 13 ms 38236 KB Output is correct
6 Correct 9 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 9 ms 37980 KB Output is correct
11 Correct 12 ms 37976 KB Output is correct
12 Correct 12 ms 38268 KB Output is correct
13 Correct 12 ms 38236 KB Output is correct
14 Correct 14 ms 38508 KB Output is correct
15 Correct 8 ms 37980 KB Output is correct
16 Correct 9 ms 37836 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 37836 KB Output is correct
2 Correct 9 ms 37980 KB Output is correct
3 Correct 181 ms 48816 KB Output is correct
4 Correct 272 ms 54940 KB Output is correct
5 Correct 258 ms 55196 KB Output is correct
6 Correct 219 ms 52968 KB Output is correct
7 Correct 243 ms 53148 KB Output is correct
8 Correct 94 ms 50400 KB Output is correct
9 Correct 263 ms 55268 KB Output is correct
10 Correct 255 ms 54540 KB Output is correct
11 Correct 232 ms 52892 KB Output is correct
12 Correct 184 ms 53128 KB Output is correct
13 Correct 192 ms 55200 KB Output is correct
14 Correct 191 ms 54632 KB Output is correct
15 Correct 195 ms 52588 KB Output is correct
16 Correct 211 ms 51880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 37980 KB Output is correct
2 Correct 764 ms 135952 KB Output is correct
3 Correct 258 ms 124940 KB Output is correct
4 Correct 673 ms 132832 KB Output is correct
5 Correct 376 ms 119824 KB Output is correct
6 Correct 213 ms 101276 KB Output is correct
7 Correct 281 ms 104200 KB Output is correct
8 Correct 167 ms 52128 KB Output is correct
9 Correct 193 ms 52456 KB Output is correct
10 Correct 110 ms 68520 KB Output is correct
11 Correct 171 ms 75240 KB Output is correct
12 Correct 760 ms 136152 KB Output is correct
13 Correct 256 ms 124768 KB Output is correct
14 Correct 700 ms 132016 KB Output is correct
15 Correct 380 ms 120140 KB Output is correct
16 Correct 207 ms 100000 KB Output is correct
17 Correct 311 ms 107932 KB Output is correct
18 Correct 592 ms 136472 KB Output is correct
19 Correct 512 ms 130620 KB Output is correct
20 Correct 624 ms 136816 KB Output is correct
21 Correct 165 ms 52028 KB Output is correct
22 Correct 201 ms 52640 KB Output is correct
23 Correct 111 ms 68472 KB Output is correct
24 Correct 171 ms 76088 KB Output is correct
25 Correct 791 ms 136164 KB Output is correct
26 Correct 250 ms 124840 KB Output is correct
27 Correct 681 ms 132260 KB Output is correct
28 Correct 380 ms 120676 KB Output is correct
29 Correct 208 ms 100576 KB Output is correct
30 Correct 302 ms 107796 KB Output is correct
31 Correct 600 ms 136120 KB Output is correct
32 Correct 522 ms 130716 KB Output is correct
33 Correct 593 ms 136820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37980 KB Output is correct
2 Correct 13 ms 38236 KB Output is correct
3 Correct 15 ms 37976 KB Output is correct
4 Correct 13 ms 37980 KB Output is correct
5 Correct 13 ms 38236 KB Output is correct
6 Correct 9 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 9 ms 37980 KB Output is correct
11 Correct 12 ms 37976 KB Output is correct
12 Correct 12 ms 38268 KB Output is correct
13 Correct 12 ms 38236 KB Output is correct
14 Correct 14 ms 38508 KB Output is correct
15 Correct 8 ms 37980 KB Output is correct
16 Correct 9 ms 37836 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 503 ms 57508 KB Output is correct
19 Correct 123 ms 42036 KB Output is correct
20 Correct 100 ms 41532 KB Output is correct
21 Correct 96 ms 41572 KB Output is correct
22 Correct 99 ms 41700 KB Output is correct
23 Correct 119 ms 42056 KB Output is correct
24 Correct 137 ms 41556 KB Output is correct
25 Correct 119 ms 41808 KB Output is correct
26 Correct 107 ms 41992 KB Output is correct
27 Correct 270 ms 54692 KB Output is correct
28 Correct 291 ms 52384 KB Output is correct
29 Correct 302 ms 55320 KB Output is correct
30 Correct 489 ms 67544 KB Output is correct
31 Correct 11 ms 37980 KB Output is correct
32 Correct 442 ms 57252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37980 KB Output is correct
2 Correct 13 ms 38236 KB Output is correct
3 Correct 15 ms 37976 KB Output is correct
4 Correct 13 ms 37980 KB Output is correct
5 Correct 13 ms 38236 KB Output is correct
6 Correct 9 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 9 ms 37980 KB Output is correct
11 Correct 12 ms 37976 KB Output is correct
12 Correct 12 ms 38268 KB Output is correct
13 Correct 12 ms 38236 KB Output is correct
14 Correct 14 ms 38508 KB Output is correct
15 Correct 8 ms 37980 KB Output is correct
16 Correct 9 ms 37836 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 503 ms 57508 KB Output is correct
19 Correct 123 ms 42036 KB Output is correct
20 Correct 100 ms 41532 KB Output is correct
21 Correct 96 ms 41572 KB Output is correct
22 Correct 99 ms 41700 KB Output is correct
23 Correct 119 ms 42056 KB Output is correct
24 Correct 137 ms 41556 KB Output is correct
25 Correct 119 ms 41808 KB Output is correct
26 Correct 107 ms 41992 KB Output is correct
27 Correct 270 ms 54692 KB Output is correct
28 Correct 291 ms 52384 KB Output is correct
29 Correct 302 ms 55320 KB Output is correct
30 Correct 489 ms 67544 KB Output is correct
31 Correct 11 ms 37980 KB Output is correct
32 Correct 442 ms 57252 KB Output is correct
33 Correct 764 ms 135952 KB Output is correct
34 Correct 258 ms 124940 KB Output is correct
35 Correct 673 ms 132832 KB Output is correct
36 Correct 376 ms 119824 KB Output is correct
37 Correct 213 ms 101276 KB Output is correct
38 Correct 281 ms 104200 KB Output is correct
39 Correct 167 ms 52128 KB Output is correct
40 Correct 193 ms 52456 KB Output is correct
41 Correct 110 ms 68520 KB Output is correct
42 Correct 171 ms 75240 KB Output is correct
43 Correct 760 ms 136152 KB Output is correct
44 Correct 256 ms 124768 KB Output is correct
45 Correct 700 ms 132016 KB Output is correct
46 Correct 380 ms 120140 KB Output is correct
47 Correct 207 ms 100000 KB Output is correct
48 Correct 311 ms 107932 KB Output is correct
49 Correct 592 ms 136472 KB Output is correct
50 Correct 512 ms 130620 KB Output is correct
51 Correct 624 ms 136816 KB Output is correct
52 Correct 165 ms 52028 KB Output is correct
53 Correct 201 ms 52640 KB Output is correct
54 Correct 111 ms 68472 KB Output is correct
55 Correct 171 ms 76088 KB Output is correct
56 Correct 791 ms 136164 KB Output is correct
57 Correct 250 ms 124840 KB Output is correct
58 Correct 681 ms 132260 KB Output is correct
59 Correct 380 ms 120676 KB Output is correct
60 Correct 208 ms 100576 KB Output is correct
61 Correct 302 ms 107796 KB Output is correct
62 Correct 600 ms 136120 KB Output is correct
63 Correct 522 ms 130716 KB Output is correct
64 Correct 593 ms 136820 KB Output is correct
65 Correct 181 ms 48816 KB Output is correct
66 Correct 272 ms 54940 KB Output is correct
67 Correct 258 ms 55196 KB Output is correct
68 Correct 219 ms 52968 KB Output is correct
69 Correct 243 ms 53148 KB Output is correct
70 Correct 94 ms 50400 KB Output is correct
71 Correct 263 ms 55268 KB Output is correct
72 Correct 255 ms 54540 KB Output is correct
73 Correct 232 ms 52892 KB Output is correct
74 Correct 184 ms 53128 KB Output is correct
75 Correct 192 ms 55200 KB Output is correct
76 Correct 191 ms 54632 KB Output is correct
77 Correct 195 ms 52588 KB Output is correct
78 Correct 211 ms 51880 KB Output is correct
79 Correct 449 ms 55760 KB Output is correct
80 Correct 525 ms 56464 KB Output is correct
81 Correct 359 ms 71852 KB Output is correct
82 Correct 374 ms 78872 KB Output is correct
83 Correct 984 ms 140288 KB Output is correct
84 Correct 442 ms 128780 KB Output is correct
85 Correct 827 ms 135580 KB Output is correct
86 Correct 543 ms 123736 KB Output is correct
87 Correct 369 ms 103540 KB Output is correct
88 Correct 416 ms 111776 KB Output is correct
89 Correct 727 ms 139592 KB Output is correct
90 Correct 837 ms 134060 KB Output is correct
91 Correct 937 ms 140216 KB Output is correct