Submission #1103676

# Submission time Handle Problem Language Result Execution time Memory
1103676 2024-10-21T14:07:06 Z Pioneer Horses (IOI15_horses) C++17
100 / 100
1295 ms 67404 KB
#include "horses.h"
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const ll inf=1e9;
const int mod=1e9+7;
const int MAX=5e6+10;

int x[MAX];
int y[MAX];

struct segtree{
	pair<int,bool> t[4*MAX];

	pair<int,bool> mrg(pair<int,bool> a,pair<int,bool> b){
		pair<int,bool> res={(int)(a.first*1ll*b.first%mod),(a.second|b.second)};
		if(a.first*1ll*b.first>=mod){
			res.second=1;
		}
		return res;
	}

	void build(int v,int tl,int tr){
		if(tl==tr){
			t[v]={x[tl],0};
			return;
		}
		int tm=(tl+tr)/2;
		build(2*v,tl,tm);
		build(2*v+1,tm+1,tr);
		t[v]=mrg(t[2*v],t[2*v+1]);
	}

	void update(int v,int tl,int tr,int pos,int x){
		if(tl==tr){
			t[v]={x,0};
			return;
		}
		int tm=(tl+tr)/2;
		if(pos<=tm)update(2*v,tl,tm,pos,x);
		else update(2*v+1,tm+1,tr,pos,x);
		t[v]=mrg(t[2*v],t[2*v+1]);
	}


	pair<int,bool> get(int v,int tl,int tr,int l,int r){
		if(l>r||tl>r||l>tr)return {1,0};
		if(l<=tl&&tr<=r)return t[v];
		int tm=(tl+tr)/2;
		return mrg(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
	}
}tx;


struct segtreeMx{
	pair<int,int> t[MAX];

	pair<int,int> mrg(pair<int,int> a,pair<int,int> b){
		if(a.first>=b.first)return a;
		else return b;
	}

	void build(int v,int tl,int tr){
		if(tl==tr){
			t[v]={y[tl],tl};
			return;
		}
		int tm=(tl+tr)/2;
		build(2*v,tl,tm);
		build(2*v+1,tm+1,tr);
		t[v]=mrg(t[2*v],t[2*v+1]);
	}

	void update(int v,int tl,int tr,int pos,int x){
		if(tl==tr){
			t[v]={x,tl};
			return;
		}
		int tm=(tl+tr)/2;
		if(pos<=tm)update(2*v,tl,tm,pos,x);
		else update(2*v+1,tm+1,tr,pos,x);
		t[v]=mrg(t[2*v],t[2*v+1]);
	}

	pair<int,int> get(int v,int tl,int tr,int l,int r){
		if(l>r||tl>r||l>tr)return {0,0};
		if(l<=tl&&tr<=r)return t[v];
		int tm=(tl+tr)/2;
		return mrg(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
	}
}ty;

int n;
set<int> st;

int get(int pos){
	int ans=1;
	// for(int i=1;i<=pos;i++)ans=(int)(ans*1ll*x[i]%mod);
	// assert(ans==tx.get(1,1,n,1,pos).first);
	// return ans*1ll*y[pos]%mod;
	return tx.get(1,1,n,1,pos).first*1ll*y[pos]%mod;
}

int get(){
	// {
	// 	int pos=n;
	// 	int per=x[n]*1ll*y[n]%mod;
	// 	bool bf=0;
	// 	if(x[n]*1ll*y[n]>=mod)bf=1;
	// 	for(int i=n-1;i>=max(1,n-1000);i--){
	// 		if(!bf&&y[i]>=per){
	// 			pos=i;
	// 			per=y[i];
	// 			bf=0;
	// 		}
	// 		if(per*1ll*x[i]>=mod){
	// 			bf=1;
	// 		}
	// 		per=per*1ll*x[i]%mod;
	// 	}
	// 	return get(pos);
	// }
	st.insert(1);
	vector<int> vec;
	int pos=ty.get(1,1,n,*st.rbegin(),n).second;
	vec.push_back(*st.rbegin());
	st.erase(--st.end());
	while(!st.empty()){
		int pos1=ty.get(1,1,n,*st.rbegin(),vec.back()-1).second;
		vec.push_back(*st.rbegin());
		st.erase(--st.end());
		pair<int,bool> bf=tx.get(1,1,n,pos1+1,pos);
		if(bf.second||bf.first*1ll*y[pos]>=mod)break;
		if(bf.first*y[pos]<=y[pos1])pos=pos1;
	}
	for(int x:vec)st.insert(x);
	return get(pos);
}

int init(int N, int X[], int Y[]) {
	// cout<<"! "<<N<<"\n";
	n=N;
	for(int i=0;i<N;i++){
		y[i+1]=Y[i];
		x[i+1]=X[i];
		if(X[i]!=1){
			st.insert(i+1);
		}
	}
	n=N;
	tx.build(1,1,n);
	ty.build(1,1,n);
	return get();
}

int updateX(int pos, int val) {	
	// return 0;
	pos++;
	if(x[pos]!=1)st.erase(pos);
	x[pos]=val;
	tx.update(1,1,n,pos,val);
	if(x[pos]!=1)st.insert(pos);
	return get();
}

int updateY(int pos, int val) {
	// return 0;
	pos++;
	y[pos]=val;
	ty.update(1,1,n,pos,val);
	return get();
}

Compilation message

horses.cpp: In member function 'void segtree::update(int, int, int, int, int)':
horses.cpp:36:46: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   36 |  void update(int v,int tl,int tr,int pos,int x){
      |                                          ~~~~^
horses.cpp:11:5: note: shadowed declaration is here
   11 | int x[MAX];
      |     ^
horses.cpp: In member function 'void segtreeMx::update(int, int, int, int, int)':
horses.cpp:76:46: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   76 |  void update(int v,int tl,int tr,int pos,int x){
      |                                          ~~~~^
horses.cpp:11:5: note: shadowed declaration is here
   11 | int x[MAX];
      |     ^
horses.cpp: In function 'int get(int)':
horses.cpp:103:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return tx.get(1,1,n,1,pos).first*1ll*y[pos]%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:99:6: warning: unused variable 'ans' [-Wunused-variable]
   99 |  int ans=1;
      |      ^~~
horses.cpp: In function 'int get()':
horses.cpp:138:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  138 |  for(int x:vec)st.insert(x);
      |          ^
horses.cpp:11:5: note: shadowed declaration is here
   11 | int x[MAX];
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6648 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6648 KB Output is correct
9 Correct 1 ms 6732 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6648 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 7 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 2 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
31 Correct 5 ms 6480 KB Output is correct
32 Correct 7 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1295 ms 55428 KB Output is correct
2 Correct 291 ms 55616 KB Output is correct
3 Correct 368 ms 55632 KB Output is correct
4 Correct 303 ms 55628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6648 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 7 ms 6636 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 2 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
31 Correct 5 ms 6628 KB Output is correct
32 Correct 7 ms 6480 KB Output is correct
33 Correct 45 ms 31348 KB Output is correct
34 Correct 41 ms 35324 KB Output is correct
35 Correct 199 ms 65408 KB Output is correct
36 Correct 165 ms 65360 KB Output is correct
37 Correct 156 ms 33356 KB Output is correct
38 Correct 109 ms 46156 KB Output is correct
39 Correct 36 ms 33100 KB Output is correct
40 Correct 162 ms 60552 KB Output is correct
41 Correct 71 ms 33108 KB Output is correct
42 Correct 106 ms 33356 KB Output is correct
43 Correct 149 ms 60936 KB Output is correct
44 Correct 150 ms 60832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6648 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 8 ms 6480 KB Output is correct
28 Correct 4 ms 6652 KB Output is correct
29 Correct 2 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 7 ms 6480 KB Output is correct
33 Correct 1205 ms 55512 KB Output is correct
34 Correct 297 ms 55628 KB Output is correct
35 Correct 377 ms 55624 KB Output is correct
36 Correct 309 ms 55624 KB Output is correct
37 Correct 40 ms 31312 KB Output is correct
38 Correct 37 ms 35152 KB Output is correct
39 Correct 183 ms 65640 KB Output is correct
40 Correct 178 ms 65600 KB Output is correct
41 Correct 150 ms 33356 KB Output is correct
42 Correct 113 ms 46156 KB Output is correct
43 Correct 35 ms 33100 KB Output is correct
44 Correct 157 ms 60492 KB Output is correct
45 Correct 73 ms 33100 KB Output is correct
46 Correct 106 ms 33356 KB Output is correct
47 Correct 146 ms 60804 KB Output is correct
48 Correct 151 ms 60824 KB Output is correct
49 Correct 200 ms 38312 KB Output is correct
50 Correct 119 ms 38220 KB Output is correct
51 Correct 501 ms 67404 KB Output is correct
52 Correct 267 ms 66900 KB Output is correct
53 Correct 1255 ms 36500 KB Output is correct
54 Correct 456 ms 50016 KB Output is correct
55 Correct 171 ms 34116 KB Output is correct
56 Correct 297 ms 62528 KB Output is correct
57 Correct 538 ms 34964 KB Output is correct
58 Correct 893 ms 35404 KB Output is correct
59 Correct 138 ms 61004 KB Output is correct