#include "rainbow.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 13;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int dir[256];
int bx1 = INT32_MAX, bx2 = INT32_MIN, by1 = INT32_MAX, by2 = INT32_MIN;
struct DS{
int bit[1001][1001] = {0};
unordered_set<ll> S;
string name;
DS(string _n) : name(_n){}
void add(int x, int y){
// cout << name << "-ADD: " << x << ' ' << y << endl;
if(S.count(x * N + y))
return;
S.insert(x * N + y);
for(int i = x; i <= 1000; i += i & -i){
for(int j = y; j <= 1000; j += j & -j){
bit[i][j] += 1;
}
}
}
int qry(int x, int y){
// cout << name << "-QRY: " << x << ' ' << y << endl;
int ret = 0;
for(int i = x; i; i -= i & -i){
for(int j = y; j; j -= j & -j){
ret += bit[i][j];
}
}
return ret;
}
int qry(int x1, int x2, int y1, int y2){
return qry(x2, y2) + qry(x1 - 1, y1 - 1) - qry(x2, y1 - 1) - qry(x1 - 1, y2);
}
} V("V"), E1("E1"), E2("E2"), SQ("SQ");
void upd(int x, int y){
bx1 = min(bx1, x);
bx2 = max(bx2, x);
by1 = min(by1, y);
by2 = max(by2, y);
V.add(x, y);
E1.add(x, y - 1);
E1.add(x, y);
E2.add(x - 1, y);
E2.add(x, y);
SQ.add(x - 1, y - 1);
SQ.add(x - 1, y);
SQ.add(x, y - 1);
SQ.add(x, y);
}
void init(int R, int C, int sr, int sc, int M, char *S) {
dir['E'] = 0;
dir['W'] = 1;
dir['S'] = 2;
dir['N'] = 3;
upd(sr, sc);
for(int i = 0; i < M; i++){
sr += dx[dir[S[i]]];
sc += dy[dir[S[i]]];
upd(sr, sc);
}
}
int colour(int ar, int ac, int br, int bc) {
int x1 = ar, x2 = br, y1 = ac, y2 = bc;
int v = (x2 - x1 + 1) * (y2 - y1 + 1) - V.qry(x1, x2, y1, y2);
int e1 = (x2 - x1 + 1) * (y2 - y1) - E1.qry(x1, x2, y1, y2 - 1);
int e2 = (x2 - x1) * (y2 - y1 + 1) - E2.qry(x1, x2 - 1, y1, y2);
int sq = (x2 - x1) * (y2 - y1) - SQ.qry(x1, x2 - 1, y1, y2 - 1);
return v - e1 - e2 + sq + (x1 < bx1 && bx2 < x2 && y1 < by1 && by2 < y2);
}
Compilation message
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:69:19: warning: array subscript has type 'char' [-Wchar-subscripts]
69 | sr += dx[dir[S[i]]];
| ~~~^
rainbow.cpp:70:19: warning: array subscript has type 'char' [-Wchar-subscripts]
70 | sc += dy[dir[S[i]]];
| ~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3067 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3065 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3067 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3067 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |