답안 #201395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201395 2020-02-10T11:17:21 Z dimash241 무지개나라 (APIO17_rainbow) C++17
100 / 100
1122 ms 86468 KB
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>
#include "rainbow.h"

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const char dc[] = {'E', 'S', 'W', 'N'};
  
int n, m, k, q;
const int MAXN = 3e5 + 5;


inline void moveto (int &x, int &y, char c) {
	if (c == 'N') x--;
	if (c == 'S') x++;
	if (c == 'W') y--;
	if (c == 'E') y++;
}
 
int lx, ly, rx, ry; 

bool cordi (int x, int y) {
	if(!(x >= lx && y >= ly && x <= rx && y <= ry)) return 0;
	return 1;
}
using pt = pair < int, int >;
vector < pt > vv[4];

struct BIT {
	vector < int > t[MAXN + 5];

	BIT () {
		for (int i = 0; i <= MAXN; ++i)
			t[i].clear();
	}
	void build() {
        for (int i = 1; i <= MAXN; ++i) {
            sort(every(t[i]));
        }
    }
 
    void upd (int x, int y) {
        if (x < 1 || y < 1) 
        	return;
 
        for (; x <= MAXN; x |= (x + 1))
            t[x].pb(y);            
        
    }

    int get (int x, int ly, int ry) {
    	ll res = 0;
        
        for (; x > 0; x = (x & (x + 1)) - 1)
            res += upper_bound(every(t[x]), ry) - lower_bound(every(t[x]), ly);
 
        return res;
    }

    int get (int lx, int rx, int ly, int ry) {
    	if (lx > rx) return 0;
    	if (ly > ry) return 0;
    	return get(rx, ly, ry) - get(lx - 1, ly, ry);
    }
	
} T[4];

void init(int _n, int _m, int x, int y, int _k, char *s) {
	n = _n, m = _m, k = _k;
	lx = rx = x;
	ly = ry = y;
	vv[0].pb(mp(x, y));
	vv[1].pb(mp(x, y));
    vv[1].pb(mp(x - 1, y));
    vv[2].pb(mp(x, y));
    vv[2].pb(mp(x, y - 1));
    vv[3].pb(mp(x, y));
    vv[3].pb(mp(x - 1, y));
    vv[3].pb(mp(x, y - 1));
	vv[3].pb(mp(x - 1, y - 1));
	

	for (int i = 0; i < k; ++i) {
		int dir = find(dc, dc + 4, s[i]) - dc;
        x += dx[dir];
        y += dy[dir];
		lx = min(lx, x);
		rx = max(rx, x);
		ly = min(ly, y);
		ry = max(ry, y);
		vv[0].pb(mp(x, y));
		vv[1].pb(mp(x, y));
        vv[1].pb(mp(x - 1, y));
        vv[2].pb(mp(x, y));
        vv[2].pb(mp(x, y - 1));
        vv[3].pb(mp(x, y));
        vv[3].pb(mp(x - 1, y));
        vv[3].pb(mp(x, y - 1));
        vv[3].pb(mp(x - 1, y - 1));
	}
	for (int i = 0; i < 4; ++i) {
		sort(every(vv[i]), [&](pt a, pt b) { return mp(a.S, a.F) < mp(b.S, b.F); });
		vv[i].resize(unique(every(vv[i])) - vv[i].begin());
		
		for (auto it : vv[i]) {
			T[i].upd(it.first, it.second);
		}
	}
} 

int colour(int ax, int ay, int bx, int by) {
	ll ans = 1;
	
	if (ax < lx && rx < bx && ay < ly && ry < by) {
        ++ans;        
    }    
 
    ans += T[1].get(ax, bx - 1, ay, by);
    ans += T[2].get(ax, bx, ay, by - 1);
    ans -= T[3].get(ax, bx - 1, ay, by - 1);
    ans -= T[0].get(ax, bx, ay, by);     
    return ans;
}
/*
static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

int main() {
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}

// B...a */
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 29048 KB Output is correct
3 Correct 28 ms 28664 KB Output is correct
4 Correct 29 ms 28664 KB Output is correct
5 Correct 31 ms 29288 KB Output is correct
6 Correct 25 ms 28536 KB Output is correct
7 Correct 25 ms 28536 KB Output is correct
8 Correct 26 ms 28540 KB Output is correct
9 Correct 26 ms 28536 KB Output is correct
10 Correct 26 ms 28536 KB Output is correct
11 Correct 29 ms 28792 KB Output is correct
12 Correct 31 ms 28920 KB Output is correct
13 Correct 30 ms 29304 KB Output is correct
14 Correct 34 ms 29720 KB Output is correct
15 Correct 26 ms 28536 KB Output is correct
16 Correct 25 ms 28536 KB Output is correct
17 Correct 25 ms 28536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 28536 KB Output is correct
2 Correct 25 ms 28536 KB Output is correct
3 Correct 221 ms 62032 KB Output is correct
4 Correct 297 ms 85872 KB Output is correct
5 Correct 295 ms 86084 KB Output is correct
6 Correct 253 ms 71492 KB Output is correct
7 Correct 285 ms 70856 KB Output is correct
8 Correct 151 ms 40128 KB Output is correct
9 Correct 335 ms 86340 KB Output is correct
10 Correct 329 ms 85572 KB Output is correct
11 Correct 275 ms 71492 KB Output is correct
12 Correct 199 ms 85060 KB Output is correct
13 Correct 211 ms 86468 KB Output is correct
14 Correct 213 ms 86084 KB Output is correct
15 Correct 200 ms 71620 KB Output is correct
16 Correct 230 ms 68164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 28536 KB Output is correct
2 Correct 113 ms 69212 KB Output is correct
3 Correct 190 ms 69056 KB Output is correct
4 Correct 155 ms 69312 KB Output is correct
5 Correct 144 ms 60524 KB Output is correct
6 Correct 126 ms 41540 KB Output is correct
7 Correct 121 ms 44948 KB Output is correct
8 Correct 212 ms 75584 KB Output is correct
9 Correct 184 ms 68676 KB Output is correct
10 Correct 82 ms 38868 KB Output is correct
11 Correct 133 ms 52164 KB Output is correct
12 Correct 112 ms 69060 KB Output is correct
13 Correct 185 ms 69060 KB Output is correct
14 Correct 159 ms 69320 KB Output is correct
15 Correct 142 ms 60356 KB Output is correct
16 Correct 114 ms 40516 KB Output is correct
17 Correct 132 ms 48708 KB Output is correct
18 Correct 185 ms 79960 KB Output is correct
19 Correct 153 ms 64836 KB Output is correct
20 Correct 154 ms 69316 KB Output is correct
21 Correct 208 ms 75668 KB Output is correct
22 Correct 188 ms 68676 KB Output is correct
23 Correct 85 ms 38864 KB Output is correct
24 Correct 129 ms 52292 KB Output is correct
25 Correct 104 ms 69060 KB Output is correct
26 Correct 183 ms 69060 KB Output is correct
27 Correct 172 ms 69316 KB Output is correct
28 Correct 143 ms 60324 KB Output is correct
29 Correct 116 ms 40520 KB Output is correct
30 Correct 129 ms 48708 KB Output is correct
31 Correct 185 ms 79812 KB Output is correct
32 Correct 155 ms 64844 KB Output is correct
33 Correct 160 ms 69352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 29048 KB Output is correct
3 Correct 28 ms 28664 KB Output is correct
4 Correct 29 ms 28664 KB Output is correct
5 Correct 31 ms 29288 KB Output is correct
6 Correct 25 ms 28536 KB Output is correct
7 Correct 25 ms 28536 KB Output is correct
8 Correct 26 ms 28540 KB Output is correct
9 Correct 26 ms 28536 KB Output is correct
10 Correct 26 ms 28536 KB Output is correct
11 Correct 29 ms 28792 KB Output is correct
12 Correct 31 ms 28920 KB Output is correct
13 Correct 30 ms 29304 KB Output is correct
14 Correct 34 ms 29720 KB Output is correct
15 Correct 26 ms 28536 KB Output is correct
16 Correct 25 ms 28536 KB Output is correct
17 Correct 25 ms 28536 KB Output is correct
18 Correct 1122 ms 58716 KB Output is correct
19 Correct 320 ms 33696 KB Output is correct
20 Correct 249 ms 32248 KB Output is correct
21 Correct 282 ms 32508 KB Output is correct
22 Correct 307 ms 32692 KB Output is correct
23 Correct 304 ms 33528 KB Output is correct
24 Correct 295 ms 32632 KB Output is correct
25 Correct 315 ms 32888 KB Output is correct
26 Correct 326 ms 33016 KB Output is correct
27 Correct 419 ms 55744 KB Output is correct
28 Correct 390 ms 46532 KB Output is correct
29 Correct 416 ms 52708 KB Output is correct
30 Correct 902 ms 83268 KB Output is correct
31 Correct 35 ms 28664 KB Output is correct
32 Correct 838 ms 57540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 29048 KB Output is correct
3 Correct 28 ms 28664 KB Output is correct
4 Correct 29 ms 28664 KB Output is correct
5 Correct 31 ms 29288 KB Output is correct
6 Correct 25 ms 28536 KB Output is correct
7 Correct 25 ms 28536 KB Output is correct
8 Correct 26 ms 28540 KB Output is correct
9 Correct 26 ms 28536 KB Output is correct
10 Correct 26 ms 28536 KB Output is correct
11 Correct 29 ms 28792 KB Output is correct
12 Correct 31 ms 28920 KB Output is correct
13 Correct 30 ms 29304 KB Output is correct
14 Correct 34 ms 29720 KB Output is correct
15 Correct 26 ms 28536 KB Output is correct
16 Correct 25 ms 28536 KB Output is correct
17 Correct 25 ms 28536 KB Output is correct
18 Correct 1122 ms 58716 KB Output is correct
19 Correct 320 ms 33696 KB Output is correct
20 Correct 249 ms 32248 KB Output is correct
21 Correct 282 ms 32508 KB Output is correct
22 Correct 307 ms 32692 KB Output is correct
23 Correct 304 ms 33528 KB Output is correct
24 Correct 295 ms 32632 KB Output is correct
25 Correct 315 ms 32888 KB Output is correct
26 Correct 326 ms 33016 KB Output is correct
27 Correct 419 ms 55744 KB Output is correct
28 Correct 390 ms 46532 KB Output is correct
29 Correct 416 ms 52708 KB Output is correct
30 Correct 902 ms 83268 KB Output is correct
31 Correct 35 ms 28664 KB Output is correct
32 Correct 838 ms 57540 KB Output is correct
33 Correct 113 ms 69212 KB Output is correct
34 Correct 190 ms 69056 KB Output is correct
35 Correct 155 ms 69312 KB Output is correct
36 Correct 144 ms 60524 KB Output is correct
37 Correct 126 ms 41540 KB Output is correct
38 Correct 121 ms 44948 KB Output is correct
39 Correct 212 ms 75584 KB Output is correct
40 Correct 184 ms 68676 KB Output is correct
41 Correct 82 ms 38868 KB Output is correct
42 Correct 133 ms 52164 KB Output is correct
43 Correct 112 ms 69060 KB Output is correct
44 Correct 185 ms 69060 KB Output is correct
45 Correct 159 ms 69320 KB Output is correct
46 Correct 142 ms 60356 KB Output is correct
47 Correct 114 ms 40516 KB Output is correct
48 Correct 132 ms 48708 KB Output is correct
49 Correct 185 ms 79960 KB Output is correct
50 Correct 153 ms 64836 KB Output is correct
51 Correct 154 ms 69316 KB Output is correct
52 Correct 208 ms 75668 KB Output is correct
53 Correct 188 ms 68676 KB Output is correct
54 Correct 85 ms 38864 KB Output is correct
55 Correct 129 ms 52292 KB Output is correct
56 Correct 104 ms 69060 KB Output is correct
57 Correct 183 ms 69060 KB Output is correct
58 Correct 172 ms 69316 KB Output is correct
59 Correct 143 ms 60324 KB Output is correct
60 Correct 116 ms 40520 KB Output is correct
61 Correct 129 ms 48708 KB Output is correct
62 Correct 185 ms 79812 KB Output is correct
63 Correct 155 ms 64844 KB Output is correct
64 Correct 160 ms 69352 KB Output is correct
65 Correct 619 ms 79148 KB Output is correct
66 Correct 656 ms 72168 KB Output is correct
67 Correct 413 ms 42376 KB Output is correct
68 Correct 518 ms 55704 KB Output is correct
69 Correct 480 ms 72644 KB Output is correct
70 Correct 882 ms 72548 KB Output is correct
71 Correct 653 ms 72800 KB Output is correct
72 Correct 572 ms 63916 KB Output is correct
73 Correct 347 ms 44128 KB Output is correct
74 Correct 402 ms 52292 KB Output is correct
75 Correct 467 ms 83456 KB Output is correct
76 Correct 747 ms 68400 KB Output is correct
77 Correct 512 ms 72900 KB Output is correct
78 Correct 221 ms 62032 KB Output is correct
79 Correct 297 ms 85872 KB Output is correct
80 Correct 295 ms 86084 KB Output is correct
81 Correct 253 ms 71492 KB Output is correct
82 Correct 285 ms 70856 KB Output is correct
83 Correct 151 ms 40128 KB Output is correct
84 Correct 335 ms 86340 KB Output is correct
85 Correct 329 ms 85572 KB Output is correct
86 Correct 275 ms 71492 KB Output is correct
87 Correct 199 ms 85060 KB Output is correct
88 Correct 211 ms 86468 KB Output is correct
89 Correct 213 ms 86084 KB Output is correct
90 Correct 200 ms 71620 KB Output is correct
91 Correct 230 ms 68164 KB Output is correct