Submission #579878

# Submission time Handle Problem Language Result Execution time Memory
579878 2022-06-20T07:22:55 Z cheetose Horses (IOI15_horses) C++17
100 / 100
599 ms 53424 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int n;
int a[500005],b[500005];
int treex[1050000],treey[1050000];
void Init(int node,int S,int E){
	if(S==E){
		treex[node]=a[S],treey[node]=b[S];
		return;
	}
	int L=node<<1,R=L|1,M=S+E>>1;
	Init(L,S,M);Init(R,M+1,E);
	treex[node]=1ll*treex[L]*treex[R]%MOD;
	treey[node]=max(treey[L],treey[R]);
}
void upd(int node,int S,int E,int i){
	if(S==E){
		treex[node]=a[S],treey[node]=b[S];
		return;
	}
	int L=node<<1,R=L|1,M=S+E>>1;
	if(i<=M)upd(L,S,M,i);
	else upd(R,M+1,E,i);
	treex[node]=1ll*treex[L]*treex[R]%MOD;
	treey[node]=max(treey[L],treey[R]);
}
int find(int node,int S,int E,int i,int j){
	if(i>E || j<S)return 0;
	if(i<=S && j>=E)return treey[node];
	int L=node<<1,R=L|1,M=S+E>>1;
	return max(find(L,S,M,i,j),find(R,M+1,E,i,j));
}
int find2(int node,int S,int E,int i,int j){
	if(i>E || j<S)return 1;
	if(i<=S && j>=E)return treex[node];
	int L=node<<1,R=L|1,M=S+E>>1;
	return 1ll*find2(L,S,M,i,j)*find2(R,M+1,E,i,j)%MOD;
}
set<int> S;
int Q(){
	if(S.empty()){
		return treey[1];
	}
	auto it=S.end();
	ll tmp=1,ttmp=1;
	it--;
	Vi v;
	while(tmp<=(ll)1e9){
		v.pb(*it);
		tmp*=a[*it];
		if(it==S.begin())break;
		it--;
	}
	reverse(ALL(v));
	__int128 mx=0;
	fup(i,0,(int)v.size()-1,1){
		ttmp*=a[v[i]];
		mx=max(mx,(__int128)ttmp*b[v[i]]);
		if(i!=(int)v.size()-1){
			mx=max(mx,(__int128)find(1,0,n-1,v[i]+1,v[i+1]-1)*ttmp);
		}else{
			mx=max(mx,(__int128)find(1,0,n-1,v[i]+1,n-1)*ttmp);
		}
	}
	if(tmp<=(ll)1e9){
		mx=max(mx,(__int128)find(1,0,n-1,0,v[0]-1));
		mx%=MOD;
	}else{
		mx=mx%MOD*find2(1,0,n-1,0,v[0]-1)%MOD;
	}
	return (int)mx;
}
int updateX(int i,int x){
	if(a[i]>1)S.erase(i);
	a[i]=x;
	if(a[i]>1)S.insert(i);
	upd(1,0,n-1,i);
	return Q();
}
int updateY(int i,int x){
	b[i]=x;
	upd(1,0,n-1,i);
	return Q();
}
int init(int N,int x[],int y[]){
	n=N;
	fup(i,0,n-1,1){
		a[i]=x[i],b[i]=y[i];
		if(a[i]>1)S.insert(i);
	}
	Init(1,0,n-1);
	return Q();
}

Compilation message

horses.cpp: In function 'void Init(int, int, int)':
horses.cpp:51:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:53:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   53 |  treex[node]=1ll*treex[L]*treex[R]%MOD;
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void upd(int, int, int, int)':
horses.cpp:61:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:64:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   64 |  treex[node]=1ll*treex[L]*treex[R]%MOD;
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int find(int, int, int, int, int)':
horses.cpp:70:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp: In function 'int find2(int, int, int, int, int)':
horses.cpp:76:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |  int L=node<<1,R=L|1,M=S+E>>1;
      |                        ~^~
horses.cpp:77:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   77 |  return 1ll*find2(L,S,M,i,j)*find2(R,M+1,E,i,j)%MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int Q()':
horses.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
horses.cpp:96:2: note: in expansion of macro 'fup'
   96 |  fup(i,0,(int)v.size()-1,1){
      |  ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
horses.cpp:127:2: note: in expansion of macro 'fup'
  127 |  fup(i,0,n-1,1){
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 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 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 561 ms 40820 KB Output is correct
2 Correct 335 ms 45312 KB Output is correct
3 Correct 328 ms 44808 KB Output is correct
4 Correct 400 ms 46044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 452 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 45 ms 20440 KB Output is correct
34 Correct 44 ms 20376 KB Output is correct
35 Correct 210 ms 50704 KB Output is correct
36 Correct 182 ms 50756 KB Output is correct
37 Correct 105 ms 18600 KB Output is correct
38 Correct 102 ms 31304 KB Output is correct
39 Correct 33 ms 18404 KB Output is correct
40 Correct 162 ms 45796 KB Output is correct
41 Correct 51 ms 18452 KB Output is correct
42 Correct 65 ms 18460 KB Output is correct
43 Correct 155 ms 46200 KB Output is correct
44 Correct 153 ms 46172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 396 KB Output is correct
24 Correct 1 ms 396 KB Output is correct
25 Correct 2 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 320 KB Output is correct
28 Correct 2 ms 324 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 554 ms 44628 KB Output is correct
34 Correct 332 ms 53424 KB Output is correct
35 Correct 336 ms 44620 KB Output is correct
36 Correct 437 ms 48440 KB Output is correct
37 Correct 43 ms 20428 KB Output is correct
38 Correct 47 ms 20400 KB Output is correct
39 Correct 179 ms 50688 KB Output is correct
40 Correct 176 ms 50680 KB Output is correct
41 Correct 93 ms 18592 KB Output is correct
42 Correct 105 ms 31316 KB Output is correct
43 Correct 31 ms 18384 KB Output is correct
44 Correct 167 ms 45760 KB Output is correct
45 Correct 51 ms 18460 KB Output is correct
46 Correct 67 ms 18484 KB Output is correct
47 Correct 166 ms 46204 KB Output is correct
48 Correct 160 ms 46124 KB Output is correct
49 Correct 168 ms 23416 KB Output is correct
50 Correct 137 ms 23396 KB Output is correct
51 Correct 344 ms 52560 KB Output is correct
52 Correct 247 ms 52088 KB Output is correct
53 Correct 599 ms 21788 KB Output is correct
54 Correct 275 ms 35332 KB Output is correct
55 Correct 125 ms 19472 KB Output is correct
56 Correct 255 ms 47516 KB Output is correct
57 Correct 303 ms 20100 KB Output is correct
58 Correct 454 ms 20620 KB Output is correct
59 Correct 152 ms 46196 KB Output is correct