답안 #1000326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000326 2024-06-17T08:51:31 Z jer033 말 (IOI15_horses) C++17
34 / 100
1500 ms 26416 KB
#include "horses.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll MOD = 1'000'000'007;
const ll INF = 1'000'000'006;
const int pus = 524288;
 
ll regmul(ll a, ll b)
{
	return (a*b)%MOD;
}
 
ll boundmul(ll a, ll b)
{
	return min(INF, a*b);
}
 
ll modpow(ll x, int y)
{
	if (y==0)
		return 1;
	if (y==1)
		return x;
	ll z = modpow(x, y/2);
	z = regmul(z, z);
	if (y%2)
		z = regmul(z, x);
	return z;
}
 
ll modinv(ll a, ll b)
{
	return regmul(a, modpow(b, MOD-2));
}
 
vector<int> x;
vector<int> y;
int n;
 
int segtree[1048576];
 
void setupsegtree()
{
	for (int i=0; i<n; i++)
	{
		segtree[pus+i] = y[i];
	}
	for (int i=pus-1; i>=1; i--)
	{
		segtree[i] = max(segtree[2*i], segtree[2*i+1]);
	}
}
 
void updatesegtree(int index, int newval)
{
	index = pus+index;
	segtree[index] = newval;
	while (index!=0)
	{
		index = index/2;
		segtree[index] = max(segtree[2*index], segtree[2*index+1]);
	}
	segtree[0] = 0;
}
 
int rangequery(int indexa, int indexb)
{
	indexa = indexa+pus;
	indexb = indexb+pus;
	int ans = -1;
	while ((indexb-indexa)>=5)
	{
		if ((indexa%2)==1)
		{
			ans = max(segtree[indexa], ans);
			indexa++;
		}
		if ((indexb%2)==0)
		{
			ans = max(segtree[indexb], ans);
			indexb--;
		}
		indexa = indexa/2;
		indexb = indexb/2;
	}
	for (int i=indexa; i<=indexb; i++)
		ans = max(segtree[i], ans);
	return ans;
}
 
priority_queue<int> nonone;
vector<int> candidates;
vector<int> mybes;
ll c;
 
void initpq()
{
	while (not nonone.empty())
		nonone.pop();
	candidates.clear();
	mybes.clear();
	c = 1;
	for (int i=0; i<n; i++)
	{
		if (x[i]>1)
		{
			nonone.push(i);
			c = regmul(c, x[i]);
		}
	}
	int j = 0;
	while ((j<30) and (not nonone.empty()))
	{
		candidates.push_back(nonone.top());
		c = modinv(c, x[nonone.top()]);
		nonone.pop();
		j++;
	}
	//reverse the list
	vector<int> newcandidates;
	for (int i=j-1; i>=0; i--)
	{
		newcandidates.push_back(candidates[i]);
	}
	candidates = newcandidates;
 
	for (int i=0; i<j; i++)
	{
		if (i!=(j-1))
		{
			mybes.push_back(rangequery(candidates[i], candidates[i+1]-1));
		}
		else
		{
			mybes.push_back(rangequery(candidates[i], n-1));
		}
	}
}
 
ll solve()
{
	int m = candidates.size();
	if (m==0)
		return rangequery(0, n-1);
	ll safe = x[candidates[0]];
	ll bes = mybes[0];
	ll currmul = 1;
	for (int i=1; i<m; i++)
	{
		if (boundmul(boundmul(currmul, x[candidates[i]]), mybes[i])>=bes)
		{
			safe = regmul(safe, currmul);
			safe = regmul(safe, x[candidates[i]]);
			currmul = 1;
			bes = mybes[i];
		}
		else
		{
			currmul = boundmul(currmul, x[candidates[i]]);
		}
	}
	ll doubans = regmul(c, regmul(safe, bes));
	return modinv(doubans, 2);
}
 
int init(int N, int X[], int Y[]) {
	x.push_back(2);
	y.push_back(1);
	for (int i=0; i<N; i++)
	{
		x.push_back(X[i]);
		y.push_back(Y[i]);
	}
	n=N+1;
	setupsegtree();
    initpq();
	return solve();
}
 
int updateX(int pos, int val) {	
	pos++;
	x[pos] = val;
	setupsegtree();
	initpq();
	return solve();
}
 
int updateY(int pos, int val) {
	pos++;
	y[pos] = val;
	updatesegtree(pos, val);
	int j = candidates.size();
	for (int i=0; i<j; i++)
	{
		if (i!=(j-1))
		{
			if ((candidates[i]<=pos) and (pos<candidates[i+1]))
				mybes[i] = rangequery(candidates[i], candidates[i+1]-1);
		}
		else
		{
			if (candidates[i]<=pos)
				mybes[i] = rangequery(candidates[i], n-1);
		}
	}
 
	return solve();
}

Compilation message

horses.cpp: In function 'll solve()':
horses.cpp:143:25: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  143 |  int m = candidates.size();
      |          ~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:178:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  178 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:186:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  186 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:193:25: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  193 |  int j = candidates.size();
      |          ~~~~~~~~~~~~~~~^~
horses.cpp:208:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  208 |  return solve();
      |         ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 6 ms 2652 KB Output is correct
23 Correct 189 ms 2652 KB Output is correct
24 Correct 179 ms 2648 KB Output is correct
25 Correct 229 ms 2652 KB Output is correct
26 Correct 227 ms 2648 KB Output is correct
27 Correct 179 ms 2660 KB Output is correct
28 Correct 367 ms 2676 KB Output is correct
29 Correct 358 ms 2672 KB Output is correct
30 Correct 367 ms 2672 KB Output is correct
31 Correct 10 ms 2652 KB Output is correct
32 Correct 191 ms 2672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 16948 KB Output is correct
2 Execution timed out 1552 ms 26416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2492 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 6 ms 2652 KB Output is correct
23 Correct 190 ms 2652 KB Output is correct
24 Correct 171 ms 2648 KB Output is correct
25 Correct 189 ms 2652 KB Output is correct
26 Correct 191 ms 2648 KB Output is correct
27 Correct 179 ms 2652 KB Output is correct
28 Correct 367 ms 2652 KB Output is correct
29 Correct 342 ms 2672 KB Output is correct
30 Correct 372 ms 2648 KB Output is correct
31 Correct 10 ms 2648 KB Output is correct
32 Correct 182 ms 2672 KB Output is correct
33 Execution timed out 1568 ms 12496 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 3 ms 2652 KB Output is correct
22 Correct 6 ms 2652 KB Output is correct
23 Correct 187 ms 2652 KB Output is correct
24 Correct 177 ms 2672 KB Output is correct
25 Correct 182 ms 2652 KB Output is correct
26 Correct 187 ms 2904 KB Output is correct
27 Correct 211 ms 2652 KB Output is correct
28 Correct 350 ms 2648 KB Output is correct
29 Correct 361 ms 2652 KB Output is correct
30 Correct 369 ms 2652 KB Output is correct
31 Correct 10 ms 2652 KB Output is correct
32 Correct 184 ms 2652 KB Output is correct
33 Correct 70 ms 16948 KB Output is correct
34 Execution timed out 1542 ms 26296 KB Time limit exceeded
35 Halted 0 ms 0 KB -