Submission #973428

# Submission time Handle Problem Language Result Execution time Memory
973428 2024-05-02T01:56:54 Z huutuan Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
1410 ms 155128 KB
#include "rainbow.h"

#include <bits/stdc++.h>

using namespace std;

const int N=2e5+20;

struct BIT2d{
   int n;
   vector<pair<int, int>> t[N];
   void init(int _n){
      n=_n;
      for (int i=1; i<=n; ++i) t[i].emplace_back(-1, 0);
   }
   void fake_update(int x, int y){
      for (int i=x; i<=n; i+=i&(-i)) t[i].emplace_back(y, 0);
   }
   void compress(){
      for (int i=1; i<=n; ++i){
         sort(t[i].begin(), t[i].end());
         t[i].resize(unique(t[i].begin(), t[i].end())-t[i].begin());
      }
   }
   void update(int x, int y, int val){
      for (int i=x; i<=n; i+=i&(-i)){
         for (int j=lower_bound(t[i].begin(), t[i].end(), make_pair(y, (int)1e9))-t[i].begin()-1; j<(int)t[i].size(); j+=j&(-j)){
            t[i][j].second+=val;
         }
      }
   }
   int get(int x, int y){
      int ans=0;
      for (int i=x; i; i-=i&(-i)){
         for (int j=lower_bound(t[i].begin(), t[i].end(), make_pair(y, (int)1e9))-t[i].begin()-1; j; j-=j&(-j)){
            ans+=t[i][j].second;
         }
      }
      return ans;
   }
   int get(int x, int y, int z, int t){
      if (x>z || y>t) return 0;
      return get(z, t)-get(z, y-1)-get(x-1, t)+get(x-1, y-1);
   }
} bit1, bit2, bit3, bit4;

const int dx[]={1, -1, 0, 0}, dy[]={0, 0, 1, -1};
int r, c;

void init(int R, int C, int sr, int sc, int M, char *S) {
   r=R, c=C;
   bit1.init(r);
   bit2.init(r+1);
   bit3.init(r+1);
   bit4.init(r);
   set<pair<int, int>> st1, st2, st3, st4;
   auto insert2=[&](int x, int y){
      st2.emplace(x, y);
      st2.emplace(x, y+1);
      st2.emplace(x+1, y);
      st2.emplace(x+1, y+1);
   };
   auto insert3=[&](int x, int y){
      st3.emplace(x, y);
      st3.emplace(x+1, y);
   };
   auto insert4=[&](int x, int y){
      st4.emplace(x, y);
      st4.emplace(x, y+1);
   };
   auto insert=[&](int x, int y){
      st1.emplace(x, y);
      insert2(x, y);
      insert3(x, y);
      insert4(x, y);
   };
   insert(sr, sc);
   for (int i=0; i<M; ++i){
      if (S[i]=='N') --sr;
      if (S[i]=='S') ++sr;
      if (S[i]=='E') ++sc;
      if (S[i]=='W') --sc;
      insert(sr, sc);
   }
   for (auto &i:st1) bit1.fake_update(i.first, i.second);
   for (auto &i:st2) bit2.fake_update(i.first, i.second);
   for (auto &i:st3) bit3.fake_update(i.first, i.second);
   for (auto &i:st4) bit4.fake_update(i.first, i.second);
   bit1.compress();
   bit2.compress();
   bit3.compress();
   bit4.compress();
   for (auto &i:st1) bit1.update(i.first, i.second, 1);
   for (auto &i:st2) bit2.update(i.first, i.second, 1);
   for (auto &i:st3) bit3.update(i.first, i.second, 1);
   for (auto &i:st4) bit4.update(i.first, i.second, 1);
}

int colour(int ar, int ac, int br, int bc) {
   int V=(br-ar+1)*2+(bc-ac+1)*2+bit2.get(ar+1, ac+1, br, bc);
   int E=(br-ar+1)*2+(bc-ac+1)*2+bit3.get(ar+1, ac, br, bc)+bit4.get(ar, ac+1, br, bc);
   int CC=1;
   int cnt_out;
   if (ar==br || ac==bc) cnt_out=bit1.get(ar, ac, br, bc);
   else cnt_out=bit1.get(ar, ac, ar, bc-1)+bit1.get(ar, bc, br-1, bc)+bit1.get(br, ac+1, br, bc)+bit1.get(ar+1, ac, br, ac);
   int cnt_in=bit1.get(ar+1, ac+1, br-1, bc-1);
   if (cnt_in && !cnt_out) ++CC;
   int F=cnt_in+cnt_out;
   // cerr << V << ' ' << E << ' ' << CC << ' ' << F << '\n';
   return E-V+CC-F;
}

# Verdict Execution time Memory Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 11 ms 19548 KB Output is correct
3 Correct 8 ms 19292 KB Output is correct
4 Correct 8 ms 19212 KB Output is correct
5 Correct 11 ms 19548 KB Output is correct
6 Correct 5 ms 19104 KB Output is correct
7 Correct 5 ms 19036 KB Output is correct
8 Correct 4 ms 19056 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19036 KB Output is correct
11 Correct 8 ms 19292 KB Output is correct
12 Correct 9 ms 19544 KB Output is correct
13 Correct 11 ms 19804 KB Output is correct
14 Correct 12 ms 20064 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 4 ms 19036 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 279 ms 44096 KB Output is correct
4 Correct 486 ms 58312 KB Output is correct
5 Correct 439 ms 58224 KB Output is correct
6 Correct 395 ms 50368 KB Output is correct
7 Correct 403 ms 50580 KB Output is correct
8 Correct 76 ms 22668 KB Output is correct
9 Correct 485 ms 58324 KB Output is correct
10 Correct 467 ms 58176 KB Output is correct
11 Correct 445 ms 50272 KB Output is correct
12 Correct 318 ms 55192 KB Output is correct
13 Correct 358 ms 58300 KB Output is correct
14 Correct 357 ms 57964 KB Output is correct
15 Correct 356 ms 50044 KB Output is correct
16 Correct 318 ms 49060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 780 ms 122408 KB Output is correct
3 Correct 442 ms 136328 KB Output is correct
4 Correct 636 ms 135204 KB Output is correct
5 Correct 432 ms 110320 KB Output is correct
6 Correct 206 ms 59864 KB Output is correct
7 Correct 321 ms 70724 KB Output is correct
8 Correct 316 ms 53200 KB Output is correct
9 Correct 326 ms 52056 KB Output is correct
10 Correct 112 ms 40888 KB Output is correct
11 Correct 256 ms 54284 KB Output is correct
12 Correct 798 ms 122320 KB Output is correct
13 Correct 425 ms 136100 KB Output is correct
14 Correct 666 ms 135524 KB Output is correct
15 Correct 453 ms 110412 KB Output is correct
16 Correct 185 ms 56792 KB Output is correct
17 Correct 355 ms 78124 KB Output is correct
18 Correct 878 ms 150664 KB Output is correct
19 Correct 681 ms 133284 KB Output is correct
20 Correct 697 ms 140220 KB Output is correct
21 Correct 303 ms 53224 KB Output is correct
22 Correct 301 ms 52032 KB Output is correct
23 Correct 120 ms 40652 KB Output is correct
24 Correct 241 ms 53960 KB Output is correct
25 Correct 766 ms 122416 KB Output is correct
26 Correct 422 ms 136332 KB Output is correct
27 Correct 667 ms 135456 KB Output is correct
28 Correct 442 ms 110488 KB Output is correct
29 Correct 188 ms 56920 KB Output is correct
30 Correct 372 ms 78124 KB Output is correct
31 Correct 882 ms 150888 KB Output is correct
32 Correct 627 ms 133292 KB Output is correct
33 Correct 702 ms 139920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 11 ms 19548 KB Output is correct
3 Correct 8 ms 19292 KB Output is correct
4 Correct 8 ms 19212 KB Output is correct
5 Correct 11 ms 19548 KB Output is correct
6 Correct 5 ms 19104 KB Output is correct
7 Correct 5 ms 19036 KB Output is correct
8 Correct 4 ms 19056 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19036 KB Output is correct
11 Correct 8 ms 19292 KB Output is correct
12 Correct 9 ms 19544 KB Output is correct
13 Correct 11 ms 19804 KB Output is correct
14 Correct 12 ms 20064 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 4 ms 19036 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 900 ms 51816 KB Output is correct
19 Correct 328 ms 23632 KB Output is correct
20 Correct 237 ms 22788 KB Output is correct
21 Correct 271 ms 22936 KB Output is correct
22 Correct 298 ms 23344 KB Output is correct
23 Correct 311 ms 23728 KB Output is correct
24 Correct 293 ms 22852 KB Output is correct
25 Correct 295 ms 23124 KB Output is correct
26 Correct 314 ms 23660 KB Output is correct
27 Correct 530 ms 44328 KB Output is correct
28 Correct 446 ms 33920 KB Output is correct
29 Correct 488 ms 42128 KB Output is correct
30 Correct 947 ms 83020 KB Output is correct
31 Correct 7 ms 19352 KB Output is correct
32 Correct 697 ms 48908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 11 ms 19548 KB Output is correct
3 Correct 8 ms 19292 KB Output is correct
4 Correct 8 ms 19212 KB Output is correct
5 Correct 11 ms 19548 KB Output is correct
6 Correct 5 ms 19104 KB Output is correct
7 Correct 5 ms 19036 KB Output is correct
8 Correct 4 ms 19056 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19036 KB Output is correct
11 Correct 8 ms 19292 KB Output is correct
12 Correct 9 ms 19544 KB Output is correct
13 Correct 11 ms 19804 KB Output is correct
14 Correct 12 ms 20064 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
16 Correct 4 ms 19036 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 900 ms 51816 KB Output is correct
19 Correct 328 ms 23632 KB Output is correct
20 Correct 237 ms 22788 KB Output is correct
21 Correct 271 ms 22936 KB Output is correct
22 Correct 298 ms 23344 KB Output is correct
23 Correct 311 ms 23728 KB Output is correct
24 Correct 293 ms 22852 KB Output is correct
25 Correct 295 ms 23124 KB Output is correct
26 Correct 314 ms 23660 KB Output is correct
27 Correct 530 ms 44328 KB Output is correct
28 Correct 446 ms 33920 KB Output is correct
29 Correct 488 ms 42128 KB Output is correct
30 Correct 947 ms 83020 KB Output is correct
31 Correct 7 ms 19352 KB Output is correct
32 Correct 697 ms 48908 KB Output is correct
33 Correct 780 ms 122408 KB Output is correct
34 Correct 442 ms 136328 KB Output is correct
35 Correct 636 ms 135204 KB Output is correct
36 Correct 432 ms 110320 KB Output is correct
37 Correct 206 ms 59864 KB Output is correct
38 Correct 321 ms 70724 KB Output is correct
39 Correct 316 ms 53200 KB Output is correct
40 Correct 326 ms 52056 KB Output is correct
41 Correct 112 ms 40888 KB Output is correct
42 Correct 256 ms 54284 KB Output is correct
43 Correct 798 ms 122320 KB Output is correct
44 Correct 425 ms 136100 KB Output is correct
45 Correct 666 ms 135524 KB Output is correct
46 Correct 453 ms 110412 KB Output is correct
47 Correct 185 ms 56792 KB Output is correct
48 Correct 355 ms 78124 KB Output is correct
49 Correct 878 ms 150664 KB Output is correct
50 Correct 681 ms 133284 KB Output is correct
51 Correct 697 ms 140220 KB Output is correct
52 Correct 303 ms 53224 KB Output is correct
53 Correct 301 ms 52032 KB Output is correct
54 Correct 120 ms 40652 KB Output is correct
55 Correct 241 ms 53960 KB Output is correct
56 Correct 766 ms 122416 KB Output is correct
57 Correct 422 ms 136332 KB Output is correct
58 Correct 667 ms 135456 KB Output is correct
59 Correct 442 ms 110488 KB Output is correct
60 Correct 188 ms 56920 KB Output is correct
61 Correct 372 ms 78124 KB Output is correct
62 Correct 882 ms 150888 KB Output is correct
63 Correct 627 ms 133292 KB Output is correct
64 Correct 702 ms 139920 KB Output is correct
65 Correct 279 ms 44096 KB Output is correct
66 Correct 486 ms 58312 KB Output is correct
67 Correct 439 ms 58224 KB Output is correct
68 Correct 395 ms 50368 KB Output is correct
69 Correct 403 ms 50580 KB Output is correct
70 Correct 76 ms 22668 KB Output is correct
71 Correct 485 ms 58324 KB Output is correct
72 Correct 467 ms 58176 KB Output is correct
73 Correct 445 ms 50272 KB Output is correct
74 Correct 318 ms 55192 KB Output is correct
75 Correct 358 ms 58300 KB Output is correct
76 Correct 357 ms 57964 KB Output is correct
77 Correct 356 ms 50044 KB Output is correct
78 Correct 318 ms 49060 KB Output is correct
79 Correct 702 ms 56416 KB Output is correct
80 Correct 846 ms 55856 KB Output is correct
81 Correct 552 ms 44332 KB Output is correct
82 Correct 641 ms 57296 KB Output is correct
83 Correct 1410 ms 125788 KB Output is correct
84 Correct 910 ms 139712 KB Output is correct
85 Correct 1295 ms 138904 KB Output is correct
86 Correct 956 ms 113744 KB Output is correct
87 Correct 615 ms 60264 KB Output is correct
88 Correct 838 ms 81696 KB Output is correct
89 Correct 1328 ms 155128 KB Output is correct
90 Correct 1194 ms 137032 KB Output is correct
91 Correct 1071 ms 143392 KB Output is correct