답안 #818124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818124 2023-08-10T02:36:19 Z jlallas384 식물 비교 (IOI20_plants) C++17
0 / 100
1 ms 468 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

struct tree{
	pair<int,int> mn;
	tree *lc, *rc;
	int l,r,lz = 0;
	tree(int i, int j, vector<int> &a){
		l = i, r = j;
		if(l == r){
			mn = {a[l], l};
			lc = nullptr , rc = nullptr;
		}else{
			int m = (l + r) / 2;
			lc = new tree(l, m, a), rc = new tree(m + 1, r, a);
			mn = min(lc->mn, rc->mn);
		}
	}
	void push(){
		if(l != r){
			lc->lz += lz;
			lc->mn.first = max(0, lc->mn.first - 1);
			rc->lz += lz;
			rc->mn.first = max(0, rc->mn.first - 1);
		}
		lz = 0;
	}
	void dec(int i, int j){
		push();
		if(i > j){
			dec(0, j), dec(i, r);
			return;
		}else if(r < i || j < l) return;
		else if(i <= l && r <= j){
			lz++;
			mn.first = max(mn.first - 1, 0);
			push();
		}else{
			lc->dec(i, j), rc->dec(i, j);
			mn = min(lc->mn, rc->mn);
		}
	}
	pair<int,int> qry(int i, int j){
		push();
		if(i > j) return min(qry(0, j), qry(i, r));
		if(r < i || j < l) return {1e9, 1e9};
		if(i <= l && r <= j) return mn;
		return min(lc->qry(i,j), rc->qry(i,j));
	}
	void rem(int i){
		push();
		if(l == r){
			mn.first = 1e9;
		}else{
			if(i <= lc->r) lc->rem(i);
			else rc->rem(i);
			mn = min(lc->mn, rc->mn);
		}
	}
	void debug(){
		push();
		if(l == r){

		}else{
			lc->debug(), rc->debug();
		}
	}
};

vector<int> ans;
void init(int k, std::vector<int> r) {
	int n = r.size();
	ans.assign(n, -1);
	tree *t = new tree(0, n - 1, r);
	set<int> st;
	for(int i = 0; i < n; i++) if(r[i] == 0){
		st.insert(i);
	}
	for(int val = n - 1; val >= 0; val--){
		cout << endl;
		vector<int> a;
		for(int x: st){
			a.push_back(x);
		}
		int x = -1;
		for(int i = 0; i < a.size(); i++){
			int prv = (i - 1 + a.size()) % a.size();
			int d = (i == 0 ? a[i] + n - a[prv] : a[i] - a[prv]);
			if(d >= k){
				x = a[i];
			}
		}
		int l = (x - k + 1 + n) % n, r = (x - 1 + n) % n;
		t->dec(l, r);
		t->debug();
		while(true){
			auto [v, i] = t->qry((x - k + 1 + n) % n, (x - 1 + n) % n);
			if(v != 0) break;
			else{
				t->rem(i);
				st.insert(i);
			}
		}
		assert(x != -1);
		ans[x] = val;
		st.erase(x);
		t->rem(x);
	}
}

int compare_plants(int x, int y) {
	if(ans[x] > ans[y]) return 1;
	else return -1;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:87:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i = 0; i < a.size(); i++){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -