Submission #1030278

# Submission time Handle Problem Language Result Execution time Memory
1030278 2024-07-22T02:06:46 Z pcc Horses (IOI15_horses) C++17
57 / 100
1500 ms 57388 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
const ll mod = 1e9+7;
const ll mxn = 5e5+10;

int N;
int arr[mxn],brr[mxn];
set<int> st;

struct SEG{
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	int mx[mxn*4];
	ll seg[mxn*4];
	void build(int now,int l,int r){
		if(l == r){
			seg[now] = arr[l];
			mx[now] = brr[l];
			return;
		}
		build(ls,l,mid);
		build(rs,mid+1,r);
		mx[now] = max(mx[ls],mx[rs]);
		seg[now] = seg[ls]*seg[rs];
		if(seg[now]>=mod)seg[now] = mod+seg[now]%mod;
		return;
	}
	void modify(int now,int l,int r,int p){
		if(l == r){
			seg[now] = arr[l];
			mx[now] = brr[l];
			return;
		}
		if(mid>=p)modify(ls,l,mid,p);
		else modify(rs,mid+1,r,p);
		mx[now] = max(mx[ls],mx[rs]);
		seg[now] = seg[ls]*seg[rs];
		if(seg[now]>=mod)seg[now] = mod+seg[now]%mod;
	}
	ll getsum(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return seg[now];
		if(mid>=e)return getsum(ls,l,mid,s,e);
		else if(mid<s)return getsum(rs,mid+1,r,s,e);
		else{
			auto re = getsum(ls,l,mid,s,e)*getsum(rs,mid+1,r,s,e);
			if(re>=mod)return mod+re%mod;
			else return re;
		}
	}
	ll getmax(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return mx[now];
		if(mid>=e)return getmax(ls,l,mid,s,e);
		else if(mid<s)return getmax(rs,mid+1,r,s,e);
		else return max(getmax(ls,l,mid,s,e),getmax(rs,mid+1,r,s,e));
	}
#undef ls
#undef rs
#undef mid
};

SEG seg;

bool cmp(int a,int b){
	if(a>b)return seg.getmax(0,0,N-1,a,N-1)*seg.getsum(0,0,N-1,b+1,a)<seg.getmax(0,0,N-1,b,N-1);
	else return seg.getmax(0,0,N-1,a,N-1)<seg.getmax(0,0,N-1,b,N-1)*seg.getsum(0,0,N-1,a+1,b);
}

ll getans(){
	st.insert(0);
	vector<int> v;
	ll pref = 1;
	for(auto it = st.rbegin();it != st.rend()&&pref<mod;it++){
		v.push_back(*it);
		pref *= arr[*it];
	}
	sort(v.begin(),v.end(),cmp);
	int tar = v.back();
	return seg.getmax(0,0,N-1,tar,N-1)*seg.getsum(0,0,N-1,0,tar)%mod;
}

int init(int NN, int X[], int Y[]) {
	N = NN;
	for(int i = 0;i<N;i++){
		arr[i] = X[i];
		if(arr[i] != 1)st.insert(i);
		brr[i] = Y[i];
	}
	seg.build(0,0,N-1);
	//cerr<<"INIT! "<<seg.getmax(0,0,N-1,0,N-1)<<endl;
	return getans();
}

int updateX(int pos, int val) {	
	arr[pos] = val;
	if(arr[pos] == 1&&st.find(pos) != st.end())st.erase(pos);
	else if(arr[pos] != 1)st.insert(pos);
	seg.modify(0,0,N-1,pos);
	return getans();
}

int updateY(int pos, int val) {
	brr[pos] = val;
	seg.modify(0,0,N-1,pos);
	return getans();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:97:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |  return getans();
      |         ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:105:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  105 |  return getans();
      |         ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:111:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |  return getans();
      |         ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6600 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6744 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6580 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 9 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 10 ms 6492 KB Output is correct
32 Correct 17 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1512 ms 48672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6540 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 9 ms 6628 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 10 ms 6492 KB Output is correct
32 Correct 17 ms 6492 KB Output is correct
33 Correct 29 ms 23564 KB Output is correct
34 Correct 26 ms 27476 KB Output is correct
35 Correct 160 ms 57388 KB Output is correct
36 Correct 141 ms 57172 KB Output is correct
37 Correct 202 ms 25152 KB Output is correct
38 Correct 69 ms 37964 KB Output is correct
39 Correct 21 ms 24916 KB Output is correct
40 Correct 120 ms 52308 KB Output is correct
41 Correct 164 ms 24916 KB Output is correct
42 Correct 284 ms 25172 KB Output is correct
43 Correct 141 ms 53240 KB Output is correct
44 Correct 121 ms 53284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6584 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 9 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 10 ms 6624 KB Output is correct
32 Correct 17 ms 6620 KB Output is correct
33 Execution timed out 1577 ms 48724 KB Time limit exceeded
34 Halted 0 ms 0 KB -