답안 #413812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413812 2021-05-29T14:28:46 Z abdzag 식물 비교 (IOI20_plants) C++17
14 / 100
4000 ms 29000 KB
#include<bits/stdc++.h>
#include "plants.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;
static const int infint = 1e9;
struct Node {
	Node* l = 0, * r = 0;
	int lo, hi, mset = inf, madd = 0, val = -inf;
	Node(int lo, int hi) :lo(lo), hi(hi) {} // Large interval of -inf
	Node(vi& v, int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo) / 2;
			l = new Node(v, lo, mid); r = new Node(v, mid, hi);
			val = min(l->val, r->val);
		}
		else val = v[lo];
	}
	int query(int L, int R) {
		if (R <= lo || hi <= L) return -inf;
		if (L <= lo && hi <= R) return val;
		push();
		return min(l->query(L, R), r->query(L, R));
	}
	void set(int L, int R, int x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) mset = val = x, madd = 0;
		else {
			push(), l->set(L, R, x), r->set(L, R, x);
			val = min(l->val, r->val);
		}
	}
	void add(int L, int R, int x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			if (mset != inf) mset += x;
			else madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = min(l->val, r->val);
		}
	}
	void push() {
		if (!l) {
			int mid = lo + (hi - lo) / 2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		if (mset != inf)
			l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf;
		else if (madd)
			l->add(lo, hi, madd), r->add(lo, hi, madd), madd = 0;
	}
};
void init(int k, std::vector<int> r) {
	ll n = r.size();
	ll indx = 0;
	Node tree(0, n);
	rep(i, 0, n)tree.set(i, i + 1, r[i]);
	rrep(j, n - 1, -1) {
		if (r[j] == 0) {
			indx = j;
			break;
		}
	}
	ll cur = 0;
	rep(j, 0, n) {
		cur++;
		if (r[(indx + j) % n] == 0) {
			if (cur > k) {
				indx = (j + indx) % n;
				break;
			}
			else cur = 1;
		}
	}
	rep(i, 0, n) {
		tree.set(indx, indx + 1, 1e9);
		sorted.push_back(indx);
		ll left = indx;
		left -= (k - 1);
		left += n;
		left %= n;
		if (left + k-1 > n) {
			tree.add(left, n, -1);
			tree.add(0, left + k - n-1, -1);
		}
		else tree.add(left, left + k-1, -1);
	    left = -1;
		ll right = 0;
		ll l = 1, r = k;
		while (l <= r) {
			ll mid = l + (r - l) / 2;
			int val;
			if (indx + mid > n) {
				val=tree.query(indx, n);
				val=min(val,tree.query(0, indx + mid- n));
			}
			else val=tree.query(indx, indx + mid);
			if (val!=0) {
				l = mid + 1;
			}
			else {
				left = indx+mid-1;
				r = mid - 1;
			}
		}
		
		int val;
		if (left != -1) {
			left %= n;
			left -= (k - 1);
			left += n;
			left %= n;
			if (left + k - 1 > n) {
				val = tree.query(left, n);
				val = min(val, tree.query(0, left + k - 1 - n));
			}
			else val = tree.query(left, left + k - 1);
			if (val != 0) {
				indx = (left + k - 1)%n;
				continue;
			}
		}
		indx -= (k - 1);
		indx += n;
		indx %= n;
		l = 0, r = k;
		while (l <= r) {
			ll mid = l + (r - l) / 2;
			int val;
			if (indx + mid > n) {
				val = tree.query(indx, n);
				val = min(val, tree.query(0, indx + mid - n));
			}
			else val = tree.query(indx, indx + mid);
			if (val!=0) {
				l = mid + 1;
			}
			else {
				right = indx + mid-1;
				r = mid - 1;
			}
		}
		right %= n;
		indx = right;
	}
	reverse(all(sorted));
}

int compare_plants(int x, int y) {
	if (find(all(sorted), x) - find(all(sorted), y) > 0)return 1;
	return -1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 9 ms 500 KB Output is correct
7 Correct 479 ms 3928 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 9 ms 460 KB Output is correct
10 Correct 477 ms 3888 KB Output is correct
11 Correct 461 ms 3884 KB Output is correct
12 Correct 471 ms 4032 KB Output is correct
13 Correct 577 ms 3904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 9 ms 500 KB Output is correct
7 Correct 479 ms 3928 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 9 ms 460 KB Output is correct
10 Correct 477 ms 3888 KB Output is correct
11 Correct 461 ms 3884 KB Output is correct
12 Correct 471 ms 4032 KB Output is correct
13 Correct 577 ms 3904 KB Output is correct
14 Correct 1778 ms 5696 KB Output is correct
15 Execution timed out 4054 ms 29000 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 349 ms 3548 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -