답안 #216918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216918 2020-03-28T12:35:12 Z kshitij_sodani 말 (IOI15_horses) C++17
100 / 100
848 ms 50424 KB
#include <iostream>
#include <bits/stdc++.h>
#include <horses.h>
using namespace std;
typedef  int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
llo mod=1000000007;
llo tree[2000001];
llo tree2[2000001];
llo tree3[2000001];
llo aa[500001];
llo bb[500001];
llo n;
llo build3(llo no,llo l,llo r){
	if(l==r){
		tree3[no]=aa[l];
	}
	else{
		llo mid=(l+r)/2;
		build3(no*2+1,l,mid);
		build3(no*2+2,mid+1,r);
		tree3[no]=(llo)(((llo)tree3[no*2+1]*tree3[no*2+2])%mod);
	}
}
llo query3(llo no,llo l,llo r,llo ac,llo bc){
	if(l>=ac and r<=bc){
		return tree3[no];
	}
	if(r<ac or bc<l){
		return 1;
	}
	llo mid=(l+r)/2;
	return (llo)(((llo)query3(no*2+1,l,mid,ac,bc)*query3(no*2+2,mid+1,r,ac,bc))%mod);
}
llo update3(llo no,llo l,llo r,llo i,llo val){
	if(l==r and l==i){
		tree3[no]=val;
	}
	else{
		llo mid=(l+r)/2;
		if(i<=mid){
			update3(no*2+1,l,mid,i,val);
		}
		else{
			update3(no*2+2,mid+1,r,i,val);
		}
		tree3[no]=(llo)(((llo)tree3[no*2+1]*tree3[no*2+2])%mod);
	}
}
llo build(llo no,llo l,llo r){
	if(l==r){
		tree[no]=aa[l];
	}
	else{
		llo mid=(l+r)/2;
		build(no*2+1,l,mid);
		build(no*2+2,mid+1,r);
		tree[no]=(llo)(min((llo)1000000001,(llo)tree[no*2+1]*tree[no*2+2]));
	}
}
llo update(llo no,llo l,llo r,llo i,llo val){
	if(l==r and l==i){
		tree[no]=val;
	}
	else{
		llo mid=(l+r)/2;
		if(i<=mid){
			update(no*2+1,l,mid,i,val);
		}
		else{
			update(no*2+2,mid+1,r,i,val);
		}
		tree[no]=(llo)(min((llo)1000000001,(llo)tree[no*2+1]*tree[no*2+2]));
	}
}
llo query(llo no,llo l,llo r,llo ac,llo bc){
	if(l>=ac and r<=bc){
		return tree[no];
	}
	if(r<ac or bc<l){
		return 1;
	}
	llo mid=(l+r)/2;
	return (llo)(min((llo)1000000001,(llo)query(no*2+1,l,mid,ac,bc)*query(no*2+2,mid+1,r,ac,bc)));
}
llo build2(llo no,llo l,llo r){
	if(l==r){
		tree2[no]=l;
	//	cout<<no<<":"<<l<<endl;
	}
	else{
		llo mid=(l+r)/2;
		build2(no*2+1,l,mid);
		build2(no*2+2,mid+1,r);
	//	cout<<l<<","<<r<<end;

		llo xx=bb[tree2[no*2+1]]/bb[tree2[no*2+2]]+1;
		if(bb[tree2[no*2+1]]%bb[tree2[no*2+2]]==0){
			xx-=1;
		}
	//	cout<<tree2[no*2+1]+1<<","<<tree2[no*2+2]<<","<<query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])<<":"<<query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])<<endl;

		if(query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])>=xx){
			tree2[no]=tree2[no*2+2];
		}
		else{
			tree2[no]=tree2[no*2+1];
		}
	//	cout<<l<<" "<<r<<" "<<no<<" "<<tree2[no]<<endl;
	}
}
llo update2(llo no,llo l,llo r,llo i){
	if(l==r and l==i){
		tree2[no]=l;
	}
	else{
		llo mid=(l+r)/2;
		if(i<=mid){
			update2(no*2+1,l,mid,i);
		}
		else{
			update2(no*2+2,mid+1,r,i);
		}
		llo xx=bb[tree2[no*2+1]]/bb[tree2[no*2+2]]+1;
		if(bb[tree2[no*2+1]]%bb[tree2[no*2+2]]==0){
			xx-=1;
		}
		if(query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])>=xx){
			tree2[no]=tree2[no*2+2];
		}
		else{
			tree2[no]=tree2[no*2+1];
		}
	}
}
int init(int nn,int x[],int y[]){

	n=(llo)nn;
	for(llo i=0;i<n;i++){	

		aa[i]=(llo)x[i];
		bb[i]=(llo)y[i];
	}
	build(0,0,n-1);
	build2(0,0,n-1);
	build3(0,0,n-1);
	return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod);
}
int updateX(int pos2,int val2){
	llo pos=pos2;
	llo val=val2;
	pos+=1;
	aa[pos-1]=val;
	update(0,0,n-1,pos-1,val);
	update3(0,0,n-1,pos-1,val);
	update2(0,0,n-1,pos-1);
	return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod);
}
int updateY(int pos2,int val2){
	llo pos=pos2;
	llo val=val2;
	pos+=1;
	bb[pos-1]=val;
	update2(0,0,n-1,pos-1);
	return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod);
}
/*int main(){
	llo k;
	cin>>k;
	llo ac[k];
	llo cc[k];
	for(llo i=0;i<k;i++){
		cin>>ac[i];
	}
	for(llo i=0;i<k;i++){
		cin>>cc[i];
	}
	llo q;
	cout<<init(k,ac,cc)<<endl;
	cin>>q;
	llo tt,mm,nn;
	for(llo i=0;i<q;i++){
		cin>>tt>>mm>>nn;
		if(tt==1){
			cout<<updateX(mm,nn)<<endl;
		}
		else{
			cout<<updateY(mm,nn)<<endl;
		}
	}
	return 0;
}*/

Compilation message

horses.cpp: In function 'llo build3(llo, llo, llo)':
horses.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update3(llo, llo, llo, llo, llo)':
horses.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo build(llo, llo, llo)':
horses.cpp:64:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update(llo, llo, llo, llo, llo)':
horses.cpp:79:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo build2(llo, llo, llo)':
horses.cpp:115:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update2(llo, llo, llo, llo)':
horses.cpp:139:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 41532 KB Output is correct
2 Correct 573 ms 50424 KB Output is correct
3 Correct 650 ms 41644 KB Output is correct
4 Correct 625 ms 45560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 228 ms 40824 KB Output is correct
34 Correct 211 ms 40824 KB Output is correct
35 Correct 206 ms 47864 KB Output is correct
36 Correct 183 ms 47736 KB Output is correct
37 Correct 184 ms 38964 KB Output is correct
38 Correct 163 ms 39800 KB Output is correct
39 Correct 143 ms 38776 KB Output is correct
40 Correct 167 ms 42744 KB Output is correct
41 Correct 154 ms 38904 KB Output is correct
42 Correct 160 ms 38904 KB Output is correct
43 Correct 155 ms 43384 KB Output is correct
44 Correct 134 ms 43128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 433 ms 41696 KB Output is correct
34 Correct 557 ms 50296 KB Output is correct
35 Correct 604 ms 41720 KB Output is correct
36 Correct 626 ms 45560 KB Output is correct
37 Correct 213 ms 40796 KB Output is correct
38 Correct 220 ms 40952 KB Output is correct
39 Correct 185 ms 47736 KB Output is correct
40 Correct 176 ms 47608 KB Output is correct
41 Correct 172 ms 39032 KB Output is correct
42 Correct 173 ms 39800 KB Output is correct
43 Correct 149 ms 38776 KB Output is correct
44 Correct 160 ms 42744 KB Output is correct
45 Correct 159 ms 38904 KB Output is correct
46 Correct 150 ms 38904 KB Output is correct
47 Correct 149 ms 43128 KB Output is correct
48 Correct 143 ms 43128 KB Output is correct
49 Correct 848 ms 42812 KB Output is correct
50 Correct 760 ms 42744 KB Output is correct
51 Correct 499 ms 49528 KB Output is correct
52 Correct 380 ms 49016 KB Output is correct
53 Correct 625 ms 41080 KB Output is correct
54 Correct 498 ms 41648 KB Output is correct
55 Correct 351 ms 39928 KB Output is correct
56 Correct 364 ms 44536 KB Output is correct
57 Correct 460 ms 40568 KB Output is correct
58 Correct 408 ms 41044 KB Output is correct
59 Correct 139 ms 43128 KB Output is correct