Submission #1030289

# Submission time Handle Problem Language Result Execution time Memory
1030289 2024-07-22T02:14:52 Z pcc Horses (IOI15_horses) C++17
100 / 100
474 ms 55048 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#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> need;
	ll pref = 1;
	for(auto it = st.rbegin();it != st.rend()&&pref<mod;it++){
		need.push_back(*it);
		pref *= arr[*it];
	}
	sort(need.begin(),need.end());
	int tar = need[0];
	for(int i = 1;i<need.size();i++){
		if(cmp(tar,need[i]))tar = need[i];
	}
	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.insert(pos);
	else if(arr[pos] == 1&&st.find(pos) != st.end())st.erase(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 'long long int getans()':
horses.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i = 1;i<need.size();i++){
      |                ~^~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:102:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  102 |  return getans();
      |         ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:110:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  110 |  return getans();
      |         ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:116:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  116 |  return getans();
      |         ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 352 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 352 KB Output is correct
23 Correct 2 ms 472 KB Output is correct
24 Correct 1 ms 556 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 474 ms 48104 KB Output is correct
2 Correct 265 ms 55048 KB Output is correct
3 Correct 268 ms 48088 KB Output is correct
4 Correct 315 ms 51024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 5 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 43 ms 23988 KB Output is correct
34 Correct 34 ms 24084 KB Output is correct
35 Correct 158 ms 52468 KB Output is correct
36 Correct 152 ms 52612 KB Output is correct
37 Correct 71 ms 22752 KB Output is correct
38 Correct 81 ms 35184 KB Output is correct
39 Correct 25 ms 22708 KB Output is correct
40 Correct 135 ms 48948 KB Output is correct
41 Correct 66 ms 22424 KB Output is correct
42 Correct 64 ms 22676 KB Output is correct
43 Correct 133 ms 49176 KB Output is correct
44 Correct 138 ms 48984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 500 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 536 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 466 ms 46932 KB Output is correct
34 Correct 266 ms 51620 KB Output is correct
35 Correct 254 ms 46988 KB Output is correct
36 Correct 329 ms 49152 KB Output is correct
37 Correct 36 ms 22868 KB Output is correct
38 Correct 39 ms 22880 KB Output is correct
39 Correct 164 ms 49640 KB Output is correct
40 Correct 153 ms 49736 KB Output is correct
41 Correct 69 ms 21872 KB Output is correct
42 Correct 82 ms 34404 KB Output is correct
43 Correct 26 ms 21888 KB Output is correct
44 Correct 136 ms 47280 KB Output is correct
45 Correct 65 ms 21904 KB Output is correct
46 Correct 76 ms 21840 KB Output is correct
47 Correct 132 ms 47296 KB Output is correct
48 Correct 152 ms 47188 KB Output is correct
49 Correct 130 ms 25448 KB Output is correct
50 Correct 93 ms 25408 KB Output is correct
51 Correct 265 ms 51196 KB Output is correct
52 Correct 203 ms 50768 KB Output is correct
53 Correct 434 ms 24572 KB Output is correct
54 Correct 266 ms 37712 KB Output is correct
55 Correct 86 ms 22448 KB Output is correct
56 Correct 188 ms 48464 KB Output is correct
57 Correct 336 ms 22864 KB Output is correct
58 Correct 414 ms 23400 KB Output is correct
59 Correct 126 ms 47292 KB Output is correct