제출 #288136

#제출 시각아이디문제언어결과실행 시간메모리
288136DystoriaX말 (IOI15_horses)C++14
54 / 100
1588 ms25992 KiB
#include "horses.h"
#include <algorithm>
#include <vector>
#include <iostream>

#define lc (i << 1)
#define rc (1 | (i << 1))

using namespace std;

const int MOD = 1e9 + 7;

int add(long long a, long long b){
	return (a + b) % MOD;
}

int mul(long long a, long long b){
	return (a * b) % MOD;
}

int st[4 * 500010];

void update(int l, int r, int pt, int val, int i){
	if(r < pt || pt < l) return;

	if(l == r && l == pt){
		st[i] = val;
		return;
	}

	int m = (l + r) >> 1;

	update(l, m, pt, val, lc);
	update(m + 1, r, pt, val, rc);

	st[i] = mul(st[lc], st[rc]);
}

int query(int l, int r, int ls, int rs, int i){
	if(r < ls || rs < l) return 1;

	if(ls <= l && r <= rs) return st[i];

	int m = (l + r) >> 1;

	return mul(query(l, m, ls, rs, lc), query(m + 1, r, ls, rs, rc));
}

int n;
vector<int> x, y;

const int MAX = 1e9;

int GetValue(){
	int idx = 0;
	long long pr = 1;
	for(int i = n - 1; i; i--){
		pr *= x[i];
		if(pr > MAX){
			idx = i; break;
		}
	}

	// for(int i = 0; i < n; i++) cerr << x[i] << " ";
	// cerr << "\n";
	// for(int i = 0; i < n; i++) cerr << y[i] << " ";
	// cerr << "\n\n";

	pr = 1;
	int opt = idx;
	for(int i = idx; i < n; i++){
		pr *= x[i];

		if(y[opt] < pr * y[i]) opt = i, pr = 1;
	}

	return mul(query(0, n - 1, 0, opt, 1), y[opt]);
}

int init(int N, int X[], int Y[]) {
	n = N;
	x.insert(x.begin(), X, X + N);
	y.insert(y.begin(), Y, Y + N);

	for(int i = 0; i < n; i++) update(0, n - 1, i, x[i], 1);

	return GetValue();
}

int updateX(int pos, int val) {	
	x[pos] = val;
	update(0, n - 1, pos, val, 1);

	return GetValue();
}

int updateY(int pos, int val) {
	y[pos] = val;

	return GetValue();
}

컴파일 시 표준 에러 (stderr) 메시지

horses.cpp: In function 'int add(long long int, long long int)':
horses.cpp:14:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   14 |  return (a + b) % MOD;
      |         ~~~~~~~~^~~~~
horses.cpp: In function 'int mul(long long int, long long int)':
horses.cpp:18:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   18 |  return (a * b) % MOD;
      |         ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...