답안 #560203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560203 2022-05-11T07:09:00 Z Koosha_mv 말 (IOI15_horses) C++14
100 / 100
506 ms 25856 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "horses.h"
 
const int N=5e5+99,mod=1e9+7;
const ll inf=1e18+mod;
 
int n,t,a[N],b[N],inv[N],mark[N],L[N],R[N],seg[N<<1];
int pd=1;
priority_queue<int> s;
 
ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}
 
void build(){
	f(i,0,n) seg[i+n]=b[i];
	f_(i,n-1,1) seg[i]=max(seg[i<<1],seg[i<<1|1]);
}
void update(int id,int val){
	seg[id]=val;
	for(id>>=1;id>0;id>>=1){
		seg[id]=max(seg[id<<1],seg[id<<1|1]);
	}
}
int get(int l,int r){
	int ans=0;
	for(l+=n,r+=n;l<r;l>>=1,r>>=1){
		if(l&1) maxm(ans,seg[l++]);
		if(r&1) maxm(ans,seg[--r]);
	}
	return ans;
}
int solve(){
	ll ans=1,res=pd;
	vector<int> vec;
	while(1){
		int i=s.top();
		s.pop();
		mark[i]=0;
		if(i==0 || a[i]>1) vec.pb(i);
		maxm(ans,1ll*a[i]*max(ans,1ll*get(i,n)));
		res=1ll*res*inv[i]%mod;
		if(s.size()==0 || ans>mod) break;
	}
	for(auto x : vec) mark[x]=1,s.push(x);
	ans%=mod;
	return 1ll*res*ans%mod;
}
int init(int _n, int X[], int Y[]) {
	n=_n;
	f(i,0,n) a[i]=X[i];
	f(i,0,n) b[i]=Y[i];
	f(i,0,n){
		inv[i]=pow(a[i],mod-2,mod);
		pd=1ll*pd*a[i]%mod;
		if(i==0 || a[i]>1) mark[i]=1,s.push(i);
	}
	build();
	return solve();
}
int updateX(int pos, int val) {
	if(a[pos]==1 && val!=1 && mark[pos]==0) mark[pos]=1,s.push(pos);
	pd=1ll*pd*pow(a[pos],mod-2,mod)%mod;
	a[pos]=val;
	pd=1ll*pd*a[pos]%mod;
	inv[pos]=pow(a[pos],mod-2,mod);
	return solve();
}
int updateY(int pos, int val) {
	b[pos]=val;
	update(pos+n,val);
	return solve();
}
/*
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n,q,a[10],b[10];
	cin>>n;
	f(i,0,n) cin>>a[i];
	f(i,0,n) cin>>b[i];
	cout<<init(n,a,b)<<endl;
	cin>>q;
	while(q--){
		int t,pos,val;
		cin>>t>>pos>>val;
		if(t==1) cout<<updateX(pos,val)<<endl;
		else cout<<updateY(pos,val)<<endl;
	}
}
 */
/*
3
2 1 3
3 4 1
1
2 1 2
*/

Compilation message

horses.cpp: In function 'long long int pow(long long int, long long int, long long int)':
horses.cpp:31:21: warning: declaration of 'mod' shadows a global declaration [-Wshadow]
   31 | ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}
      |                     ^
horses.cpp:24:20: note: shadowed declaration is here
   24 | const int N=5e5+99,mod=1e9+7;
      |                    ^~~
horses.cpp: In function 'int solve()':
horses.cpp:65:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   65 |  return 1ll*res*ans%mod;
      |         ~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:72:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   72 |   inv[i]=pow(a[i],mod-2,mod);
      |          ~~~^~~~~~~~~~~~~~~~
horses.cpp:73:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   73 |   pd=1ll*pd*a[i]%mod;
      |      ~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:81:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |  pd=1ll*pd*pow(a[pos],mod-2,mod)%mod;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:83:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   83 |  pd=1ll*pd*a[pos]%mod;
      |     ~~~~~~~~~~~~~^~~~
horses.cpp:84:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   84 |  inv[pos]=pow(a[pos],mod-2,mod);
      |           ~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 316 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 324 KB Output is correct
29 Correct 2 ms 320 KB Output is correct
30 Correct 2 ms 320 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 19248 KB Output is correct
2 Correct 387 ms 19116 KB Output is correct
3 Correct 364 ms 19132 KB Output is correct
4 Correct 396 ms 19160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 324 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 324 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 153 ms 16076 KB Output is correct
34 Correct 155 ms 16148 KB Output is correct
35 Correct 297 ms 18256 KB Output is correct
36 Correct 295 ms 18232 KB Output is correct
37 Correct 173 ms 15232 KB Output is correct
38 Correct 216 ms 17204 KB Output is correct
39 Correct 146 ms 14156 KB Output is correct
40 Correct 273 ms 18244 KB Output is correct
41 Correct 140 ms 14284 KB Output is correct
42 Correct 148 ms 14192 KB Output is correct
43 Correct 265 ms 18112 KB Output is correct
44 Correct 271 ms 18156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 392 KB Output is correct
29 Correct 3 ms 324 KB Output is correct
30 Correct 3 ms 400 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 505 ms 19148 KB Output is correct
34 Correct 368 ms 19192 KB Output is correct
35 Correct 361 ms 19124 KB Output is correct
36 Correct 389 ms 19152 KB Output is correct
37 Correct 136 ms 16232 KB Output is correct
38 Correct 130 ms 16240 KB Output is correct
39 Correct 298 ms 18304 KB Output is correct
40 Correct 252 ms 18276 KB Output is correct
41 Correct 159 ms 15228 KB Output is correct
42 Correct 197 ms 17280 KB Output is correct
43 Correct 128 ms 14156 KB Output is correct
44 Correct 252 ms 18324 KB Output is correct
45 Correct 150 ms 14284 KB Output is correct
46 Correct 131 ms 14284 KB Output is correct
47 Correct 242 ms 18180 KB Output is correct
48 Correct 270 ms 18236 KB Output is correct
49 Correct 200 ms 17340 KB Output is correct
50 Correct 210 ms 17376 KB Output is correct
51 Correct 380 ms 19240 KB Output is correct
52 Correct 306 ms 19252 KB Output is correct
53 Correct 490 ms 16348 KB Output is correct
54 Correct 304 ms 22336 KB Output is correct
55 Correct 243 ms 17144 KB Output is correct
56 Correct 380 ms 25856 KB Output is correct
57 Correct 203 ms 17864 KB Output is correct
58 Correct 290 ms 18268 KB Output is correct
59 Correct 247 ms 24492 KB Output is correct