Submission #414915

# Submission time Handle Problem Language Result Execution time Memory
414915 2021-05-31T10:36:36 Z abdzag Comparing Plants (IOI20_plants) C++17
0 / 100
66 ms 12628 KB
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int inf = -1e9;

using namespace std;

vector<ll> sorted(3e5);
static const int infint = 1e9;
struct Node{
	typedef pair<int,int> T;
	T unit = make_pair(-inf,-inf);
	ll l, r;
	int mset = inf, madd = 0;
	T val;
	Node* lnode = 0,* rnode = 0;
	T f(T a, T b) { return min(a,b); }
	Node(ll l,ll r) : l(l), r(r) {}
	Node(vector<T> & v, ll l, ll r) : l(l) , r(r) {
		if (l + 1 == r)val = v[l];
		else {
			ll mid = l + (r - l) / 2;
			lnode = new Node(v, l, mid);
			rnode = new Node(v, mid, r);
			val = f(lnode->val, rnode->val);
		}
	}
	void set(ll lo, ll hi, int x) {
		if (lo >= r || hi <= l)return;
		if (lo <= l && hi >= r) {
			mset = val.first = x;
			madd = 0;
		}
		else {
			push();
			lnode->set(lo, hi, x);
			rnode->set(lo, hi, x);
			val = f(lnode->val, rnode->val);
		}
	}
	void add(ll lo, ll hi, int x) {
		if (lo >= r || hi <= l)return;
		if (lo <= l && hi >= r) {
			if (mset != inf) {
				mset += x;
			}
			else madd += x;
			val.first += x;
		}
		else {
			push();
			lnode->add(lo, hi, x);
			rnode->add(lo, hi, x);
			val = f(lnode->val, rnode->val);
		}
	}
	T query(ll lo, ll hi) {
		if (lo >= r || hi <= l)return unit;
		if (lo <= l && hi >= r) return val;
		else return f(lnode->query(lo, hi), rnode->query(lo, hi));
	}
	void push() {
		if (!lnode) {
			ll mid = l + (l - r) / 2;
			lnode = new Node(l, mid);
			rnode = new Node(mid, r);
		}
		if (mset != inf) {
			lnode->set(l, r, mset);
			rnode->set(l, r, mset);
			mset = inf;
		}
		else if (madd) {
			lnode->add(l, r, madd);
			rnode->add(l, r, madd);
			madd = 0;
		}
	}
};
ll counter = 0;
vector<bitset<302>> reachable(302);
vector<vector<ll>> g(302);
vector<bool> visited(302);
vector<bool> visited0(302);
void dfs(ll cur) {
	visited[cur] = 1;
	trav(v, g[cur]) {
		if (visited[v] == 0) {
			dfs(v);
		}
		reachable[cur] |= reachable[v];
	}
	return;
}
void extract(Node*& tree, ll cur, ll k, ll n) {
	if (cur - k + 1 < 0) {
		while (!tree->query(0, cur).first) {
			extract(tree, tree->query(0, cur).second, k, n);
		}
		while (!tree->query(n - (k - 1 - cur), n).first) {
			extract(tree, tree->query(n - (k - 1 - cur), n).second, k, n);
		}
		tree->add(0, cur, -1);
		tree->add(n - (k - 1 - cur), n, -1);

		rep(j, (n - (k - 1 - cur)), n) {
			if (tree->query(j, j + 1).first < 1e6)g[cur].push_back(j);
		}
		rep(j, 0, cur) {
			if (tree->query(j, j + 1).first < 1e6)g[cur].push_back(j);
		}
	}
	else {
		while (!tree->query(cur - k + 1, cur).first) {
			extract(tree, tree->query(cur - k + 1, cur).second, k, n);
		}
		tree->add(cur - k + 1, cur, -1);
		rep(j, cur - k + 1, cur) {
			if (tree->query(j, j + 1).first < 1e6)g[cur].push_back(j);
		}
	}
	rep(j, cur + 1, cur + k) {
		if (tree->query(j % n, j % n + 1).first < 1e6)g[cur].push_back(j % n);
	}
	tree->set(cur, cur + 1, infint);
	return;
}
void init(int k, std::vector<int> r) {
	ll n = r.size();
	ll indx = 0;
	rep(i, 0, n)reachable[i][i] = 1;
	vector<pair<int, int>> v;
	rep(i, 0, n)v.emplace_back(r[i], i);
	Node* tree = new Node(v, 0, n);
	rep(i, 0, n) {
		pair<int, int> val = tree->query(0, n);
		if (val.first == 0)extract(tree, val.second, k, n);
		else break;
	}
}

int compare_plants(int x, int y) {
	dfs(x);
	dfs(y);
	if (reachable[x][y])return 1;
	else if (reachable[y][x]) return -1;
	return 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:138:5: warning: unused variable 'indx' [-Wunused-variable]
  138 |  ll indx = 0;
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 66 ms 6408 KB Output is correct
7 Runtime error 52 ms 12628 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2676 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 5 ms 2764 KB Output is correct
6 Runtime error 12 ms 5836 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2676 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 5 ms 2764 KB Output is correct
6 Runtime error 12 ms 5836 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2676 KB Output is correct
3 Runtime error 51 ms 12432 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Incorrect 4 ms 2764 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2672 KB Output is correct
3 Correct 2 ms 2672 KB Output is correct
4 Incorrect 2 ms 2636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 66 ms 6408 KB Output is correct
7 Runtime error 52 ms 12628 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -