답안 #795363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795363 2023-07-27T08:38:21 Z Josia 말 (IOI15_horses) C++17
컴파일 오류
0 ms 0 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
// #define int long long

constexpr ll mod = 1e9+7;

struct seg {
	vector<int> tree;
	array<int, 2000000> tree;

	void init(int n) {
		// tree.assign(n*4, 0);
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = x;
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = max(tree[v*2], tree[v*2+1]);
	}

	int query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return 0;

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


struct segY {
	vector<pair<int, int>> tree;

	void init(int n) {
		tree.assign(n*4, {0, 0});
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = {x, pos};
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = max(tree[v*2], tree[v*2+1]);
	}

	pair<int, int> query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return {0, -1};

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


ll mult(ll a, ll b) {
	int res = a*b;
	if (res >= mod) res%=mod;
	return res;
}

struct seg2 {
	vector<ll> tree;

	void init(int n) {
		tree.assign(n*4, 0);
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = x;
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = mult(tree[v*2], tree[v*2+1]);
	}

	ll query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return 1;

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return mult(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


seg tree;
segY treeY;
seg2 tree2;
int N;
vector<ll> X, Y;

struct getSol {
	int sol = 0;

	int BS(int pos) {
		if (pos == 0) return -1;
		int l = 0, r = pos-1;
		while (l<r) {
			int m = (l+r+1)/2;
			if (tree.query(1, 0, N-1, m, pos-1) > 1) {
				l = m;
			} else {
				r = m-1;
			}
		}

		return l;
	}

	int BSinv(int pos) {
		if (pos == N-1) return N-1;
		int l = pos+1, r = N-1;
		while (l<r) {
			int m = (l+r+1)/2;
			if (tree.query(1, 0, N-1, pos+1, m) > 1) {
				r = m-1;
			} else {
				l = m;
			}
		}

		return l;
	}


	int findInd() {
		int currInd = N-1;
		ll currProd = 1;
		for (int i = N-1; i>=0; i = BS(i)) {
			auto bestSell = treeY.query(1, 0, N-1, i, BSinv(i));
			if (currProd*Y[currInd] <= bestSell.first) {currInd = bestSell.second; currProd=1;}

			currProd *= X[i];
			if (currProd*Y[currInd] > 1e9) break;
		}
		return currInd;
	}


	getSol() {
		int ind = findInd();

		sol = (tree2.query(1, 0, N-1, 0, ind) * Y[ind])%mod;
	}
};




signed init(signed _N, signed _X[], signed _Y[]) {
	N = _N;
	X.resize(N);
	Y.resize(N);
	for (int i = 0; i<N; i++) X[i] = _X[i];
	for (int i = 0; i<N; i++) Y[i] = _Y[i];

	tree.init(N);
	treeY.init(N);
	tree2.init(N);

	for (int i = 0; i<N; i++) {
		tree.update(1, 0, N-1, i, X[i]);
		treeY.update(1, 0, N-1, i, Y[i]);
		tree2.update(1, 0, N-1, i, X[i]);
	}
	return getSol().sol;
}

signed updateX(signed pos, signed val) {
	tree.update(1, 0, N-1, pos, val);
	tree2.update(1, 0, N-1, pos, val);
	X[pos] = val;

	return getSol().sol;
}

signed updateY(signed pos, signed val) {
	treeY.update(1, 0, N-1, pos, val);
	Y[pos] = val;

	return getSol().sol;
}

Compilation message

horses.cpp:13:22: error: redeclaration of 'std::array<int, 2000000> seg::tree'
   13 |  array<int, 2000000> tree;
      |                      ^~~~
horses.cpp:12:14: note: previous declaration 'std::vector<int> seg::tree'
   12 |  vector<int> tree;
      |              ^~~~
horses.cpp: In member function 'void seg::init(int)':
horses.cpp:15:16: warning: unused parameter 'n' [-Wunused-parameter]
   15 |  void init(int n) {
      |            ~~~~^
horses.cpp: In function 'long long int mult(long long int, long long int)':
horses.cpp:79:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   79 |  int res = a*b;
      |            ~^~
horses.cpp: In member function 'int getSol::findInd()':
horses.cpp:165:16: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  165 |    if (currProd*Y[currInd] > 1e9) break;
horses.cpp: In constructor 'getSol::getSol()':
horses.cpp:174:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  174 |   sol = (tree2.query(1, 0, N-1, 0, ind) * Y[ind])%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:193:33: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  193 |   tree.update(1, 0, N-1, i, X[i]);
      |                                 ^
horses.cpp:194:34: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  194 |   treeY.update(1, 0, N-1, i, Y[i]);
      |                                  ^
horses.cpp:195:34: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  195 |   tree2.update(1, 0, N-1, i, X[i]);
      |                                  ^