답안 #620844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620844 2022-08-03T09:40:19 Z Hazem 말 (IOI15_horses) C++14
17 / 100
242 ms 44732 KB
#include <bits/stdc++.h>
#define LL long long
#define F first
#define S second

using namespace std;

const int M = 5e5+10;
const int MOD = 1e9+7;

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

LL mult(LL a,LL b){
	return (a*b)%MOD;
}

LL fastpow(LL n,LL k){

	LL ret = 1;

	while(k){

		if(k&1)ret = mult(ret,n);
		k /= 2;
		n = mult(n,n);
	}
	return ret;
}

LL divide(LL a,LL b){
	return mult(a,fastpow(b,MOD-2));
}

LL a[M],b[M],tree[M*4],n;
LL pr = 1;
set<int>st;

void update(int v,int tl,int tr,int pos,int val){

	if(tl==tr){
		tree[v] = val;
		return ;
	}

	int mid = (tl+tr)/2;
	if(pos<=mid)
		update(v*2,tl,mid,pos,val);
	else 
		update(v*2+1,mid+1,tr,pos,val);

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

LL get(int v,int tl,int tr,int l,int r){

	if(tl>r||tr<l)
		return 1;

	if(tl>=l&&tr<=r)
		return tree[v];

	int mid = (tl+tr)/2;
	return max(get(v*2,tl,mid,l,r),get(v*2+1,mid+1,tr,l,r));
}

LL calc(){

	vector<pair<LL,LL>>vec;
	int cnt = 0;
	int last = n+1;
	for(auto it:st){
		if(cnt==30)
			break;
		
		cnt++;
		int idx = -(it);
		if(last-idx>1)
			vec.push_back({1,get(1,1,n,idx+1,last-1)});
		
		last = idx;
		vec.push_back({a[idx],b[idx]});
	}
	if(vec.empty())
		vec.push_back({1,get(1,1,n,1,n)});
	
	reverse(vec.begin(),vec.end());
	LL idx = 0,cur = 1;
	for(int i = 1;i<vec.size();i++){
		
		if((cur*vec[i].F>vec[idx].S)||(cur*vec[i].F*vec[i].S>vec[idx].S))
			idx = i,cur = 1;
		else 
			cur *= vec[i].F;
	}

	cur = 1;
	for(int i=0;i<=idx;i++)
		cur = mult(cur,vec[i].F);
	
	return mult(cur,vec[idx].S);
}

int init(int N, int X[], int Y[]) {
	
	n = N;
	a[0] = 1;
	for(int i=1;i<=n;i++){
		a[i] = X[i-1];
		b[i] = Y[i-1];
		update(1,1,n,i,b[i]);

		if(a[i]>1)
			st.insert(-i);
	}

	return calc();
}

int updateX(int pos, int val) {	

	if(a[pos+1]>1)
		st.erase(-pos-1);

	a[pos+1] = val;
	if(a[pos+1]>1)
		st.insert(-pos-1);

	return calc();
}

int updateY(int pos, int val) {
	
	b[pos+1] = val;
	update(1,1,n,pos+1,b[pos+1]);

	return calc();
}

Compilation message

horses.cpp: In function 'long long int calc()':
horses.cpp:72:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   72 |  int last = n+1;
      |             ~^~
horses.cpp:80:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   80 |    vec.push_back({1,get(1,1,n,idx+1,last-1)});
      |                             ^
horses.cpp:86:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |   vec.push_back({1,get(1,1,n,1,n)});
      |                            ^
horses.cpp:86:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |   vec.push_back({1,get(1,1,n,1,n)});
      |                                ^
horses.cpp:90:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for(int i = 1;i<vec.size();i++){
      |                ~^~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:112:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |   update(1,1,n,i,b[i]);
      |              ^
horses.cpp:112:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |   update(1,1,n,i,b[i]);
      |                  ~~~^
horses.cpp:118:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  118 |  return calc();
      |         ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:130:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  130 |  return calc();
      |         ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:136:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  136 |  update(1,1,n,pos+1,b[pos+1]);
      |             ^
horses.cpp:136:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  136 |  update(1,1,n,pos+1,b[pos+1]);
      |                     ~~~~~~~^
horses.cpp:138:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  138 |  return calc();
      |         ~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 236 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 5 ms 340 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 242 ms 44732 KB Output isn't correct
2 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 4 ms 380 KB Output isn't correct
24 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 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 4 ms 340 KB Output isn't correct
24 Halted 0 ms 0 KB -