답안 #201398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201398 2020-02-10T11:20:21 Z dimash241 무지개나라 (APIO17_rainbow) C++17
100 / 100
1111 ms 71396 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[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k, q;
const int MAXN = 2e5 + 1;
 
 
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++;
//	assert(x > 0 && y > 0 && x <= n && y <= m);
} 
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];
 
    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 rx, int ly, int ry) {
    	int res = 0;
    	while (rx >= 0) {
    		res += upper_bound(every(t[rx]), ry) 
    			- lower_bound(every(t[rx]), ly);
    		rx = (rx & (rx + 1)) - 1;
    	}
 
    	return res;
    }
 
    int get (int lx, int rx, int ly, int ry) {
    	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) {
		moveto(x, y, s[i]);
		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 19 ms 19192 KB Output is correct
2 Correct 21 ms 19576 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19320 KB Output is correct
5 Correct 23 ms 19832 KB Output is correct
6 Correct 17 ms 19096 KB Output is correct
7 Correct 18 ms 19192 KB Output is correct
8 Correct 18 ms 19192 KB Output is correct
9 Correct 16 ms 19192 KB Output is correct
10 Correct 17 ms 19064 KB Output is correct
11 Correct 20 ms 19320 KB Output is correct
12 Correct 21 ms 19448 KB Output is correct
13 Correct 24 ms 19832 KB Output is correct
14 Correct 26 ms 20220 KB Output is correct
15 Correct 16 ms 19192 KB Output is correct
16 Correct 17 ms 19064 KB Output is correct
17 Correct 17 ms 19192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19064 KB Output is correct
2 Correct 17 ms 19192 KB Output is correct
3 Correct 221 ms 48340 KB Output is correct
4 Correct 296 ms 70724 KB Output is correct
5 Correct 298 ms 71396 KB Output is correct
6 Correct 261 ms 57620 KB Output is correct
7 Correct 280 ms 56260 KB Output is correct
8 Correct 142 ms 27972 KB Output is correct
9 Correct 309 ms 70692 KB Output is correct
10 Correct 301 ms 70212 KB Output is correct
11 Correct 273 ms 58128 KB Output is correct
12 Correct 181 ms 70348 KB Output is correct
13 Correct 225 ms 70212 KB Output is correct
14 Correct 191 ms 70340 KB Output is correct
15 Correct 185 ms 57284 KB Output is correct
16 Correct 233 ms 53828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19192 KB Output is correct
2 Correct 95 ms 56008 KB Output is correct
3 Correct 171 ms 57156 KB Output is correct
4 Correct 146 ms 56384 KB Output is correct
5 Correct 135 ms 48836 KB Output is correct
6 Correct 107 ms 31552 KB Output is correct
7 Correct 111 ms 34500 KB Output is correct
8 Correct 192 ms 63940 KB Output is correct
9 Correct 177 ms 57540 KB Output is correct
10 Correct 97 ms 28756 KB Output is correct
11 Correct 122 ms 41160 KB Output is correct
12 Correct 98 ms 56008 KB Output is correct
13 Correct 178 ms 57268 KB Output is correct
14 Correct 143 ms 56388 KB Output is correct
15 Correct 132 ms 48704 KB Output is correct
16 Correct 103 ms 30656 KB Output is correct
17 Correct 122 ms 38340 KB Output is correct
18 Correct 167 ms 66984 KB Output is correct
19 Correct 142 ms 52788 KB Output is correct
20 Correct 150 ms 57160 KB Output is correct
21 Correct 197 ms 63984 KB Output is correct
22 Correct 177 ms 57412 KB Output is correct
23 Correct 75 ms 28748 KB Output is correct
24 Correct 122 ms 41156 KB Output is correct
25 Correct 96 ms 56008 KB Output is correct
26 Correct 168 ms 57136 KB Output is correct
27 Correct 141 ms 56388 KB Output is correct
28 Correct 132 ms 48708 KB Output is correct
29 Correct 106 ms 30656 KB Output is correct
30 Correct 122 ms 38264 KB Output is correct
31 Correct 171 ms 67012 KB Output is correct
32 Correct 144 ms 52804 KB Output is correct
33 Correct 149 ms 57152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 21 ms 19576 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19320 KB Output is correct
5 Correct 23 ms 19832 KB Output is correct
6 Correct 17 ms 19096 KB Output is correct
7 Correct 18 ms 19192 KB Output is correct
8 Correct 18 ms 19192 KB Output is correct
9 Correct 16 ms 19192 KB Output is correct
10 Correct 17 ms 19064 KB Output is correct
11 Correct 20 ms 19320 KB Output is correct
12 Correct 21 ms 19448 KB Output is correct
13 Correct 24 ms 19832 KB Output is correct
14 Correct 26 ms 20220 KB Output is correct
15 Correct 16 ms 19192 KB Output is correct
16 Correct 17 ms 19064 KB Output is correct
17 Correct 17 ms 19192 KB Output is correct
18 Correct 1111 ms 45064 KB Output is correct
19 Correct 306 ms 21368 KB Output is correct
20 Correct 240 ms 20088 KB Output is correct
21 Correct 269 ms 20344 KB Output is correct
22 Correct 298 ms 20736 KB Output is correct
23 Correct 295 ms 21244 KB Output is correct
24 Correct 294 ms 20472 KB Output is correct
25 Correct 303 ms 20728 KB Output is correct
26 Correct 318 ms 20984 KB Output is correct
27 Correct 406 ms 42180 KB Output is correct
28 Correct 389 ms 33900 KB Output is correct
29 Correct 380 ms 39364 KB Output is correct
30 Correct 861 ms 67832 KB Output is correct
31 Correct 20 ms 19192 KB Output is correct
32 Correct 724 ms 44044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 21 ms 19576 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19320 KB Output is correct
5 Correct 23 ms 19832 KB Output is correct
6 Correct 17 ms 19096 KB Output is correct
7 Correct 18 ms 19192 KB Output is correct
8 Correct 18 ms 19192 KB Output is correct
9 Correct 16 ms 19192 KB Output is correct
10 Correct 17 ms 19064 KB Output is correct
11 Correct 20 ms 19320 KB Output is correct
12 Correct 21 ms 19448 KB Output is correct
13 Correct 24 ms 19832 KB Output is correct
14 Correct 26 ms 20220 KB Output is correct
15 Correct 16 ms 19192 KB Output is correct
16 Correct 17 ms 19064 KB Output is correct
17 Correct 17 ms 19192 KB Output is correct
18 Correct 1111 ms 45064 KB Output is correct
19 Correct 306 ms 21368 KB Output is correct
20 Correct 240 ms 20088 KB Output is correct
21 Correct 269 ms 20344 KB Output is correct
22 Correct 298 ms 20736 KB Output is correct
23 Correct 295 ms 21244 KB Output is correct
24 Correct 294 ms 20472 KB Output is correct
25 Correct 303 ms 20728 KB Output is correct
26 Correct 318 ms 20984 KB Output is correct
27 Correct 406 ms 42180 KB Output is correct
28 Correct 389 ms 33900 KB Output is correct
29 Correct 380 ms 39364 KB Output is correct
30 Correct 861 ms 67832 KB Output is correct
31 Correct 20 ms 19192 KB Output is correct
32 Correct 724 ms 44044 KB Output is correct
33 Correct 95 ms 56008 KB Output is correct
34 Correct 171 ms 57156 KB Output is correct
35 Correct 146 ms 56384 KB Output is correct
36 Correct 135 ms 48836 KB Output is correct
37 Correct 107 ms 31552 KB Output is correct
38 Correct 111 ms 34500 KB Output is correct
39 Correct 192 ms 63940 KB Output is correct
40 Correct 177 ms 57540 KB Output is correct
41 Correct 97 ms 28756 KB Output is correct
42 Correct 122 ms 41160 KB Output is correct
43 Correct 98 ms 56008 KB Output is correct
44 Correct 178 ms 57268 KB Output is correct
45 Correct 143 ms 56388 KB Output is correct
46 Correct 132 ms 48704 KB Output is correct
47 Correct 103 ms 30656 KB Output is correct
48 Correct 122 ms 38340 KB Output is correct
49 Correct 167 ms 66984 KB Output is correct
50 Correct 142 ms 52788 KB Output is correct
51 Correct 150 ms 57160 KB Output is correct
52 Correct 197 ms 63984 KB Output is correct
53 Correct 177 ms 57412 KB Output is correct
54 Correct 75 ms 28748 KB Output is correct
55 Correct 122 ms 41156 KB Output is correct
56 Correct 96 ms 56008 KB Output is correct
57 Correct 168 ms 57136 KB Output is correct
58 Correct 141 ms 56388 KB Output is correct
59 Correct 132 ms 48708 KB Output is correct
60 Correct 106 ms 30656 KB Output is correct
61 Correct 122 ms 38264 KB Output is correct
62 Correct 171 ms 67012 KB Output is correct
63 Correct 144 ms 52804 KB Output is correct
64 Correct 149 ms 57152 KB Output is correct
65 Correct 584 ms 64728 KB Output is correct
66 Correct 632 ms 58304 KB Output is correct
67 Correct 380 ms 29520 KB Output is correct
68 Correct 471 ms 41924 KB Output is correct
69 Correct 469 ms 56900 KB Output is correct
70 Correct 825 ms 58048 KB Output is correct
71 Correct 636 ms 57156 KB Output is correct
72 Correct 555 ms 49476 KB Output is correct
73 Correct 314 ms 31396 KB Output is correct
74 Correct 371 ms 38980 KB Output is correct
75 Correct 440 ms 67756 KB Output is correct
76 Correct 690 ms 53700 KB Output is correct
77 Correct 489 ms 57904 KB Output is correct
78 Correct 221 ms 48340 KB Output is correct
79 Correct 296 ms 70724 KB Output is correct
80 Correct 298 ms 71396 KB Output is correct
81 Correct 261 ms 57620 KB Output is correct
82 Correct 280 ms 56260 KB Output is correct
83 Correct 142 ms 27972 KB Output is correct
84 Correct 309 ms 70692 KB Output is correct
85 Correct 301 ms 70212 KB Output is correct
86 Correct 273 ms 58128 KB Output is correct
87 Correct 181 ms 70348 KB Output is correct
88 Correct 225 ms 70212 KB Output is correct
89 Correct 191 ms 70340 KB Output is correct
90 Correct 185 ms 57284 KB Output is correct
91 Correct 233 ms 53828 KB Output is correct