Submission #1018656

# Submission time Handle Problem Language Result Execution time Memory
1018656 2024-07-10T07:54:42 Z amirhoseinfar1385 Horses (IOI15_horses) C++17
100 / 100
1373 ms 60576 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=500000+10,mod=1e9+7,lg=19,kaf=(1<<(lg));
int allx[maxn],ally[maxn],n;
set<int>st;
struct segment{
	struct node{
		int maxa,zarb;
		node(){
			maxa=0;
			zarb=1;
		}
	};
	node seg[(1<<(lg+1))];
	void upd(int i,int w){
		i+=kaf;
		seg[i].zarb=seg[i].maxa=w;
		i>>=1;
		while(i>0){
			seg[i].maxa=max(seg[(i<<1)].maxa,seg[(i<<1)^1].maxa);
			seg[i].zarb=1ll*seg[(i<<1)].zarb*seg[(i<<1)^1].zarb%mod;
			i>>=1;
		}
	}
	int porszarb(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl||tl>tr){
			return 1;
		}
		if(l>=tl&&r<=tr){
			return seg[i].zarb;
		}
		int m=(l+r)>>1;
		return 1ll*porszarb((i<<1),l,m,tl,tr)*porszarb((i<<1)^1,m+1,r,tl,tr)%mod;
	}
	int porsmx(int i,int l,int r,int tl,int tr){
		int ret=0;
		tl+=kaf;
		ret=max(ret,seg[tl].maxa);
		while(tl>1){
			if(tl&1){
				tl>>=1;
			}else{
				ret=max(ret,seg[tl^1].maxa);
				tl>>=1;
			}
		}
		return ret;
	}
}segx,segy;
int calc(){
	long long unnow=1;
	vector<int>ind;
	while((int)st.size()>0){
		unnow*=allx[(*st.rbegin())];
		ind.push_back((*st.rbegin()));
		st.erase((*st.rbegin()));
		if(unnow>1000000000){
			break;
		}
	}
	unnow/=allx[ind.back()];
	long long mx=0;
	for(int i=0;i<(int)ind.size();i++){
		mx=max(mx,unnow*segy.porsmx(1,0,kaf-1,ind[i],n));
		unnow/=allx[ind[i]];
	}
	mx%=mod;
	mx*=segx.porszarb(1,0,kaf-1,0,ind.back());
	mx%=mod;
	for(auto x:ind){
		st.insert(x);
	}
	return mx;
}

int init(int N, int X[], int Y[]) {
	n=N;
	allx[0]=1;
	st.insert(0);
	for(int i=1;i<=n;i++){
		//cout<<i<<endl;
		allx[i]=X[i-1];
		segx.upd(i,allx[i]);
		ally[i]=Y[i-1];
		segy.upd(i,ally[i]);
		if(allx[i]>1){
			st.insert(i);
		}
	}
	return calc();
}

int updateX(int pos, int val) {
	pos++;	
	allx[pos]=val;
	if(allx[pos]==1){
		st.erase(pos);
	}else{
		st.insert(pos);
	}
	segx.upd(pos,val);
	return calc();
}

int updateY(int pos, int val) {
	pos++;
	ally[pos]=val;
	segy.upd(pos,val);
	return calc();
}

Compilation message

horses.cpp: In member function 'void segment::upd(int, int)':
horses.cpp:22:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   22 |    seg[i].zarb=1ll*seg[(i<<1)].zarb*seg[(i<<1)^1].zarb%mod;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int segment::porszarb(int, int, int, int, int)':
horses.cpp:34:71: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   34 |   return 1ll*porszarb((i<<1),l,m,tl,tr)*porszarb((i<<1)^1,m+1,r,tl,tr)%mod;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int segment::porsmx(int, int, int, int, int)':
horses.cpp:36:17: warning: unused parameter 'i' [-Wunused-parameter]
   36 |  int porsmx(int i,int l,int r,int tl,int tr){
      |             ~~~~^
horses.cpp:36:23: warning: unused parameter 'l' [-Wunused-parameter]
   36 |  int porsmx(int i,int l,int r,int tl,int tr){
      |                   ~~~~^
horses.cpp:36:29: warning: unused parameter 'r' [-Wunused-parameter]
   36 |  int porsmx(int i,int l,int r,int tl,int tr){
      |                         ~~~~^
horses.cpp:36:42: warning: unused parameter 'tr' [-Wunused-parameter]
   36 |  int porsmx(int i,int l,int r,int tl,int tr){
      |                                      ~~~~^~
horses.cpp: In function 'int calc()':
horses.cpp:74:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   74 |  return mx;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 17032 KB Output is correct
4 Correct 5 ms 16836 KB Output is correct
5 Correct 3 ms 16984 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 5 ms 17028 KB Output is correct
9 Correct 5 ms 16988 KB Output is correct
10 Correct 5 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 5 ms 16904 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 5 ms 16836 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16824 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 4 ms 16988 KB Output is correct
3 Correct 4 ms 16824 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 5 ms 17032 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 4 ms 17032 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 5 ms 16984 KB Output is correct
16 Correct 4 ms 16828 KB Output is correct
17 Correct 4 ms 16988 KB Output is correct
18 Correct 4 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 17012 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 4 ms 16988 KB Output is correct
25 Correct 5 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 6 ms 17008 KB Output is correct
28 Correct 5 ms 16988 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 4 ms 16988 KB Output is correct
31 Correct 5 ms 16984 KB Output is correct
32 Correct 6 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1373 ms 52840 KB Output is correct
2 Correct 401 ms 60500 KB Output is correct
3 Correct 474 ms 52516 KB Output is correct
4 Correct 550 ms 56148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Correct 3 ms 17008 KB Output is correct
7 Correct 3 ms 16984 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 17032 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16796 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 4 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 4 ms 17048 KB Output is correct
25 Correct 5 ms 17112 KB Output is correct
26 Correct 5 ms 16988 KB Output is correct
27 Correct 6 ms 16988 KB Output is correct
28 Correct 5 ms 16988 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 4 ms 16988 KB Output is correct
31 Correct 5 ms 16988 KB Output is correct
32 Correct 6 ms 16988 KB Output is correct
33 Correct 142 ms 28532 KB Output is correct
34 Correct 141 ms 28500 KB Output is correct
35 Correct 282 ms 58168 KB Output is correct
36 Correct 262 ms 58204 KB Output is correct
37 Correct 165 ms 26964 KB Output is correct
38 Correct 219 ms 39508 KB Output is correct
39 Correct 133 ms 26708 KB Output is correct
40 Correct 252 ms 53768 KB Output is correct
41 Correct 149 ms 26704 KB Output is correct
42 Correct 152 ms 26672 KB Output is correct
43 Correct 239 ms 53892 KB Output is correct
44 Correct 244 ms 53860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 4 ms 17028 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 17028 KB Output is correct
16 Correct 3 ms 16836 KB Output is correct
17 Correct 3 ms 16996 KB Output is correct
18 Correct 3 ms 16852 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16824 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 4 ms 17080 KB Output is correct
24 Correct 4 ms 16988 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 6 ms 16988 KB Output is correct
28 Correct 5 ms 17116 KB Output is correct
29 Correct 4 ms 16984 KB Output is correct
30 Correct 6 ms 16988 KB Output is correct
31 Correct 6 ms 16984 KB Output is correct
32 Correct 9 ms 16988 KB Output is correct
33 Correct 1360 ms 52872 KB Output is correct
34 Correct 388 ms 60576 KB Output is correct
35 Correct 471 ms 52560 KB Output is correct
36 Correct 518 ms 56284 KB Output is correct
37 Correct 141 ms 28520 KB Output is correct
38 Correct 135 ms 28716 KB Output is correct
39 Correct 279 ms 58200 KB Output is correct
40 Correct 272 ms 58172 KB Output is correct
41 Correct 158 ms 26964 KB Output is correct
42 Correct 213 ms 39552 KB Output is correct
43 Correct 132 ms 26492 KB Output is correct
44 Correct 246 ms 53808 KB Output is correct
45 Correct 150 ms 26592 KB Output is correct
46 Correct 152 ms 26848 KB Output is correct
47 Correct 238 ms 53840 KB Output is correct
48 Correct 250 ms 53864 KB Output is correct
49 Correct 219 ms 31568 KB Output is correct
50 Correct 197 ms 31568 KB Output is correct
51 Correct 573 ms 59832 KB Output is correct
52 Correct 360 ms 59424 KB Output is correct
53 Correct 480 ms 29932 KB Output is correct
54 Correct 569 ms 43348 KB Output is correct
55 Correct 187 ms 27680 KB Output is correct
56 Correct 332 ms 55376 KB Output is correct
57 Correct 296 ms 28244 KB Output is correct
58 Correct 386 ms 28812 KB Output is correct
59 Correct 245 ms 53952 KB Output is correct