Submission #288744

# Submission time Handle Problem Language Result Execution time Memory
288744 2020-09-01T20:30:29 Z Saboon Land of the Rainbow Gold (APIO17_rainbow) C++17
24 / 100
527 ms 84448 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
map<char,int> adjr = {{'N', -1}, {'S', 1}};
map<char,int> adjc = {{'E', 1}, {'W', -1}};
set<pair<int,int>> Snake;
int R, C;
pair<int,int> Snakex, Snakey;

struct Segment2D{
	vector<int> fen[maxn], fex[maxn];
	vector<pair<int,int>> Q;
	int get(int X, int Y){
		int ret = 0;
		for (int x = X; x; x -= x & -x){
			int y = upper_bound(fex[x].begin(),fex[x].end(),Y)-fex[x].begin();
			for (; y; y -= y & -y)
				ret += fen[x][y-1];
		}
		return ret;
	}
	int get(int x1, int x2, int y1, int y2){
		if (x2 < x1 or y2 < y1)
			return 0;
		return get(x2, y2) - get(x2, y1-1) - get(x1-1, y2) + get(x1-1,y1-1);
	}
	void addreal(int X, int Y){
		for (int x = X; x < maxn; x += x & -x){
			int y = lower_bound(fex[x].begin(),fex[x].end(),Y)-fex[x].begin()+1;
			for (; y <= fen[x].size(); y += y & -y)
				fen[x][y-1] ++;
		}
	}
	void add(int X, int Y){
		for (int x = X; x < maxn; x += x & -x)
			fex[x].push_back(Y);
		Q.push_back({X,Y});
	}
	void build(){
		for (int i = 1; i < maxn; i++){
			sort(fex[i].begin(),fex[i].end());
			fex[i].resize(unique(fex[i].begin(),fex[i].end())-fex[i].begin());
			fen[i].resize(fex[i].size());
		}
		sort(Q.begin(),Q.end());
		Q.resize(unique(Q.begin(),Q.end())-Q.begin());
		for (auto it : Q)
			addreal(it.first, it.second);
	}
} seg[6];

void init(int r, int c, int sr, int sc, int M, char *S){
	R = r, C = c;
	Snake.insert({sr,sc});
	Snakex = {sr,sr};
	Snakey = {sc,sc};
	seg[0].add(sr,sc);
	for (int i = 0; i < M; i++){
		sr += adjr[S[i]], sc += adjc[S[i]];
		Snake.insert({sr,sc});
		seg[0].add(sr,sc);
		Snakex.first = min(Snakex.first,sr), Snakex.second = max(Snakex.second,sr);
		Snakey.first = min(Snakey.first,sc), Snakey.second = max(Snakey.second,sc);
	}
	for (auto it : Snake){
		int x = it.first, y = it.second;
		if (Snake.count({x-1,y}))
			seg[1].add(x,y);
		if (Snake.count({x,y-1}))
			seg[2].add(x,y);
		if (Snake.count({x,y-1}) and Snake.count({x-1,y}) and Snake.count({x-1,y-1}))
			seg[3].add(x,y);
		if (Snake.count({x-1,y-1}) and !Snake.count({x-1,y}) and !Snake.count({x,y-1}))
			seg[4].add(x,y);
		if (Snake.count({x-1,y+1}) and !Snake.count({x-1,y}) and !Snake.count({x,y+1}))
			seg[5].add(x,y+1);
	}
	for (int i = 0; i < 6; i++)
		seg[i].build();
}

int colour(int x1, int y1, int x2, int y2){
	int v = seg[0].get(x1, x2, y1, y2) + 2*(x2-x1+y2-y1+4);
	int e = seg[1].get(x1+1, x2, y1, y2) + seg[2].get(x1,x2, y1+1,y2)
		  + seg[0].get(x1, x1, y1, y2) + seg[0].get(x2, x2, y1, y2) + seg[0].get(x1, x2, y1, y1) + seg[0].get(x1, x2, y2, y2)
		  + 2*(x2-x1+y2-y1+4) + seg[4].get(x1+1, x2, y1+1, y2) + seg[5].get(x1+1, x2, y1+1, y2);
	int c = 1 + (Snakex.first > x1 and Snakex.second < x2 and Snakey.first > y1 and Snakey.second < y2);
	int f = seg[3].get(x1+1, x2, y1+1, y2) + seg[1].get(x1+1, x2, y1, y2) - seg[1].get(x1+1, x2, y1+1, y2-1)
		  + seg[2].get(x1, x2, y1+1, y2) - seg[2].get(x1+1, x2-1, y1+1, y2) + Snake.count({x1,y1}) + Snake.count({x1,y2})
		  + Snake.count({x2,y1}) + Snake.count({x2,y2});
	return c + e - v - f;
}

Compilation message

rainbow.cpp: In member function 'void Segment2D::addreal(int, int)':
rainbow.cpp:31:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for (; y <= fen[x].size(); y += y & -y)
      |           ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 56824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 56704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 56704 KB Output is correct
2 Correct 248 ms 76348 KB Output is correct
3 Correct 185 ms 81376 KB Output is correct
4 Correct 339 ms 84324 KB Output is correct
5 Correct 190 ms 75084 KB Output is correct
6 Correct 179 ms 67408 KB Output is correct
7 Correct 240 ms 70072 KB Output is correct
8 Correct 527 ms 83992 KB Output is correct
9 Correct 464 ms 80200 KB Output is correct
10 Correct 153 ms 63576 KB Output is correct
11 Correct 211 ms 68040 KB Output is correct
12 Correct 252 ms 76476 KB Output is correct
13 Correct 185 ms 81380 KB Output is correct
14 Correct 342 ms 84320 KB Output is correct
15 Correct 189 ms 75088 KB Output is correct
16 Correct 166 ms 66896 KB Output is correct
17 Correct 278 ms 74048 KB Output is correct
18 Correct 322 ms 76548 KB Output is correct
19 Correct 233 ms 80332 KB Output is correct
20 Correct 247 ms 81868 KB Output is correct
21 Correct 523 ms 83896 KB Output is correct
22 Correct 457 ms 80276 KB Output is correct
23 Correct 174 ms 63452 KB Output is correct
24 Correct 276 ms 67912 KB Output is correct
25 Correct 250 ms 76496 KB Output is correct
26 Correct 182 ms 81380 KB Output is correct
27 Correct 337 ms 84448 KB Output is correct
28 Correct 186 ms 75088 KB Output is correct
29 Correct 164 ms 66940 KB Output is correct
30 Correct 278 ms 73800 KB Output is correct
31 Correct 315 ms 76340 KB Output is correct
32 Correct 232 ms 80288 KB Output is correct
33 Correct 247 ms 81992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 56824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 56824 KB Output isn't correct
2 Halted 0 ms 0 KB -