답안 #1090539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090539 2024-09-18T12:36:21 Z owoovo 말 (IOI15_horses) C++17
37 / 100
336 ms 61268 KB
#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
#define ld double
#define F first 
#define S second
#define lc id*2+1
#define rc id*2+2
using namespace std;
const ll p=1e9+7;
ll pw(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)ans*=a,ans%=p;
		b>>=1,a*=a,a%=p;
	}
	return ans;
}
ll x[500010],y[500010],n;
struct BIT{
	ll ori[500010];
	void init(){
		for(int i=0;i<=n;i++)ori[i]=1;
		return;
	}
	void modify(ll x,int pos){
		while(pos<=n){
			ori[pos]*=x;
			ori[pos]%=p;
			pos+=pos&(-pos);
		}
		return;
	}
	ll query(ll pos){
		ll ans=1;
		while(pos){
			ans*=ori[pos];
			ans%=p;
			pos-=pos&(-pos);
		}
		return ans;
	}
}bit;
struct SEG_TREE{
	pair<int,int> ori[2000010];
	void build(int l,int r,int id){
		if(l==r){
			ori[id]={y[l],l};
			return;
		}
		int m=(l+r)>>1;
		build(l,m,lc);
		build(m+1,r,rc);
		ori[id]=max(ori[lc],ori[rc]);
		return;
	}
	void modify(int l,int r,int pos,int id,int x){
		if(l==pos&&r==pos){
			ori[id]={x,l};
			return;
		}
		int m=(l+r)>>1;
		if(pos<=m){
			modify(l,m,pos,lc,x);
		}else{
			modify(m+1,r,pos,rc,x);
		}
		ori[id]=max(ori[lc],ori[rc]);
		return;
	}
	pair<int,int> query(int l,int r,int ql,int qr,int id){
		if(l==ql&&r==qr){
			return ori[id];
		}
		int m=(l+r)>>1;
		if(qr<=m){
			return query(l,m,ql,qr,lc);
		}else if(m<ql){
			return query(m+1,r,ql,qr,rc);
		}else{
			return max(query(l,m,ql,m,lc),query(m+1,r,m+1,qr,rc));
		}
	}
}seg;

set<int> big;

ll q(){
	ll now=1;
	if(big.size()==1){
		return seg.query(1,n,1,n,0).F;
	}
	set<int>::iterator k=(--(--big.end()));
	ll ans=0,pos=0;
	ld nw=0;
	ld maxn=0;
	while(now<=1e9&&k!=big.begin()){
		now*=x[*k];
		k--;
	}
	while(k!=(--big.end())){
		nw+=log2(x[*k]);
		set<int>::iterator nx=k;
		nx++;
		//cout<<*k<<" "<<*(nx)<<"\n";
		pair<int,int> pp=seg.query(1,n,*k,*(nx)-1,0);
		//cout<<pp.F<<" "<<pp.S<<"\n";
		if(maxn<nw+log2(pp.F)){
			maxn=nw+log2(pp.F);
			pos=pp.S;
		}
		k=nx;
	}
	ll a=bit.query(pos);
	//cout<<a<<"?\n";
	a*=y[pos];
	//cout<<a<<" 888\n";
	a%=p;
	//cout<<pos<<"\n";
	return a;
}

int init(int N, int X[], int Y[]) {
	n=N;
	big.insert(n+1);
	bit.init();
	for(int i=0;i<n;i++){
		x[i+1]=X[i];
		bit.modify(x[i+1],i+1);
		if(x[i+1]>1)big.insert(i+1);
		y[i+1]=Y[i];
	}
	seg.build(1,n,0);
	return q();
}

int updateX(int pos, int val) {	
	pos+=1;
	bit.modify((pw(x[pos],p-2)*val)%p,pos);
	x[pos]=val;
	if(val==1)big.erase(pos);
	else big.insert(pos);
	return q();
}

int updateY(int pos, int val) {
	pos+=1;
	seg.modify(1,n,pos,0,val);
	y[pos]=val;
	return q();
}

Compilation message

horses.cpp: In member function 'void BIT::modify(long long int, int)':
horses.cpp:26:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   26 |  void modify(ll x,int pos){
      |                 ^
horses.cpp:19:4: note: shadowed declaration is here
   19 | ll x[500010],y[500010],n;
      |    ^
horses.cpp: In member function 'void SEG_TREE::modify(int, int, int, int, int)':
horses.cpp:57:45: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   57 |  void modify(int l,int r,int pos,int id,int x){
      |                                         ~~~~^
horses.cpp:19:4: note: shadowed declaration is here
   19 | ll x[500010],y[500010],n;
      |    ^
horses.cpp: In function 'long long int q()':
horses.cpp:91:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |   return seg.query(1,n,1,n,0).F;
      |                      ^
horses.cpp:91:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |   return seg.query(1,n,1,n,0).F;
      |                          ^
horses.cpp:97:8: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   97 |  while(now<=1e9&&k!=big.begin()){
      |        ^~~
horses.cpp:106:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  106 |   pair<int,int> pp=seg.query(1,n,*k,*(nx)-1,0);
      |                                ^
horses.cpp:94:5: warning: unused variable 'ans' [-Wunused-variable]
   94 |  ll ans=0,pos=0;
      |     ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:125:14: warning: conversion from 'long long int' to 'std::set<int>::value_type' {aka 'int'} may change value [-Wconversion]
  125 |  big.insert(n+1);
      |             ~^~
horses.cpp:133:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  133 |  seg.build(1,n,0);
      |              ^
horses.cpp:134:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  134 |  return q();
      |         ~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:143:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  143 |  return q();
      |         ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:148:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  148 |  seg.modify(1,n,pos,0,val);
      |               ^
horses.cpp:150:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  150 |  return q();
      |         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 352 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 448 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 360 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 2 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 336 ms 52564 KB Output is correct
2 Correct 280 ms 61268 KB Output is correct
3 Correct 230 ms 52560 KB Output is correct
4 Correct 277 ms 56240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 444 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 2 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 444 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 536 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Incorrect 2 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -