답안 #683824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683824 2023-01-19T12:16:39 Z S2speed 무지개나라 (APIO17_rainbow) C++17
36 / 100
494 ms 189864 KB
#include "rainbow.h"
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define sze(x) (int)(x.size())
#define mp(x , y) make_pair(x , y)
#define wall cout<<"--------------------------------------\n";
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;
typedef double db;
typedef pair<pll , ll> plll;
typedef pair<int , pii> piii;
typedef pair<pll , pll> pllll;

const ll maxn = 2e5 + 17 , md = 1e9 + 7 , inf = 2e8;

vector<int> merge(vector<int> &a , vector<int> &b){
	vector<int> res;
	int as = sze(a) , bs = sze(b);
	a.push_back(inf); b.push_back(inf);
	int x = 0 , y = 0;
	for(int e = 0 ; e < as + bs ; e++){
		if(a[x] < b[y]){
			res.push_back(a[x++]);
		} else {
			res.push_back(b[y++]);
		}
	}
	a.pop_back(); b.pop_back();
	return res;
}

struct segtree {

	int sz = 1;
	vector<vector<int>> val;

	void init(int n){
		while(sz < n) sz <<= 1;
		val.resize(sz << 1);
		return;
	}

	void add(int i , int k , int x , int lx , int rx){
		if(rx - lx == 1){
			val[x].push_back(k);
			return;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		if(i < m){
			add(i , k , ln , lx , m);
		} else {
			add(i , k , rn , m , rx);
		}
		return;
	}

	void add(int i , int k){
		add(i , k , 0 , 0 , sz);
		return;
	}

	void build(int x , int lx , int rx){
		if(rx - lx == 1){
			sort(all(val[x]));
			val[x].resize(distance(val[x].begin() , unique(all(val[x]))));
			return;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		build(ln , lx , m); build(rn , m , rx);
		val[x] = merge(val[ln] , val[rn]);
		return;
	}

	void build(){
		build(0 , 0 , sz);
		return;
	}

	int cal(int l1 , int r1 , int l2 , int r2 , int x , int lx , int rx){
		if(rx <= l1 || lx >= r1) return 0;
		if(rx <= r1 && lx >= l1){
			int res = lower_bound(all(val[x]) , r2) - lower_bound(all(val[x]) , l2);
			return res;
		}
		int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
		int a = cal(l1 , r1 , l2 , r2 , ln , lx , m) , b = cal(l1 , r1 , l2 , r2 , rn , m , rx);
		return a + b;
	}

	int cal(int l1 , int r1 , int l2 , int r2){
		return cal(l1 , r1 , l2 , r2 , 0 , 0 , sz);
	}

};

segtree v , e[2] , f;
vector<int> vx[maxn] , vy[maxn];

void add(int x , int y){
	v.add(x , y);
	e[0].add(x - 1 , y); e[0].add(x , y);
	e[1].add(x , y - 1); e[1].add(x , y);
	f.add(x - 1 , y - 1); f.add(x - 1 , y); f.add(x , y - 1); f.add(x , y);
	vx[x].push_back(y); vy[y].push_back(x);
	return;
}

void init(int n , int m , int sx , int sy , int k , char *s){
	v.init(n + 1); e[0].init(n + 1); e[1].init(n + 1); f.init(n + 1);
	int x = sx , y = sy;
	for(int i = 0 ; ; i++){
		add(x , y);
		if(i == k) break;
		if(s[i] == 'N'){
			x--;
		} else if(s[i] == 'S'){
			x++;
		} else if(s[i] == 'E'){
			y++;
		} else {
			y--;
		}
	}
	v.build(); e[0].build(); e[1].build(); f.build();
	return;
}

bool mohit(int x1 , int y1 , int x2 , int y2){
	int res = 0;
	res += lower_bound(all(vx[x1]) , y2) - lower_bound(all(vx[x1]) , y1);
	res += lower_bound(all(vx[x2 - 1]) , y2) - lower_bound(all(vx[x2 - 1]) , y1);
	res += lower_bound(all(vy[y1]) , x2) - lower_bound(all(vy[y1]) , x1);
	res += lower_bound(all(vy[y2 - 1]) , x2) - lower_bound(all(vy[y2 - 1]) , x1);
	return (res > 0);
}

int colour(int l1 , int l2 , int r1 , int r2){
	r1++; r2++;
	ll h = v.cal(l1 , r1 , l2 , r2);
	if(h == 0) return 1;
	ll V = 1ll * (r1 - l1) * (r2 - l2) - h;
	ll E = 1ll * (r1 - l1) * (r2 - l2 - 1) + 1ll * (r1 - l1 - 1) * (r2 - l2);
	E -= e[0].cal(l1 , r1 - 1 , l2 , r2) + e[1].cal(l1 , r1 , l2 , r2 - 1);
	ll F = 1ll * (r1 - l1 - 1) * (r2 - l2 - 1) - f.cal(l1 , r1 - 1 , l2 , r2 - 1) + 1 + !mohit(l1 , l2 , r1 , r2);
	return V - E + F - 1;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9696 KB Output is correct
3 Correct 144 ms 19940 KB Output is correct
4 Correct 215 ms 24708 KB Output is correct
5 Correct 192 ms 24568 KB Output is correct
6 Correct 149 ms 22340 KB Output is correct
7 Correct 194 ms 22228 KB Output is correct
8 Correct 94 ms 16696 KB Output is correct
9 Correct 218 ms 24808 KB Output is correct
10 Correct 202 ms 24488 KB Output is correct
11 Correct 170 ms 22428 KB Output is correct
12 Correct 105 ms 24168 KB Output is correct
13 Correct 110 ms 24736 KB Output is correct
14 Correct 104 ms 24508 KB Output is correct
15 Correct 119 ms 22448 KB Output is correct
16 Correct 137 ms 21376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 301 ms 175200 KB Output is correct
3 Correct 410 ms 189808 KB Output is correct
4 Correct 429 ms 183872 KB Output is correct
5 Correct 395 ms 170604 KB Output is correct
6 Correct 339 ms 140492 KB Output is correct
7 Correct 309 ms 148440 KB Output is correct
8 Correct 61 ms 23736 KB Output is correct
9 Correct 77 ms 25244 KB Output is correct
10 Correct 148 ms 78576 KB Output is correct
11 Correct 197 ms 94324 KB Output is correct
12 Correct 298 ms 175256 KB Output is correct
13 Correct 387 ms 189864 KB Output is correct
14 Correct 354 ms 183836 KB Output is correct
15 Correct 348 ms 170692 KB Output is correct
16 Correct 276 ms 137952 KB Output is correct
17 Correct 290 ms 149284 KB Output is correct
18 Correct 311 ms 176332 KB Output is correct
19 Correct 350 ms 182484 KB Output is correct
20 Correct 344 ms 182564 KB Output is correct
21 Correct 66 ms 23776 KB Output is correct
22 Correct 79 ms 25252 KB Output is correct
23 Correct 154 ms 78464 KB Output is correct
24 Correct 196 ms 94224 KB Output is correct
25 Correct 331 ms 175240 KB Output is correct
26 Correct 413 ms 189840 KB Output is correct
27 Correct 418 ms 183888 KB Output is correct
28 Correct 494 ms 170704 KB Output is correct
29 Correct 289 ms 137840 KB Output is correct
30 Correct 354 ms 149280 KB Output is correct
31 Correct 344 ms 176300 KB Output is correct
32 Correct 404 ms 182632 KB Output is correct
33 Correct 423 ms 182636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -