Submission #590788

# Submission time Handle Problem Language Result Execution time Memory
590788 2022-07-06T11:12:47 Z FatihSolak Horses (IOI15_horses) C++17
57 / 100
1500 ms 48368 KB
#include "horses.h"
#include <bits/stdc++.h>
#define N 500005
using namespace std;
const int mod = 1e9 + 7;
struct node{
	int maxi;
	int prod = 1;
	node(int a,int b){
		maxi = a;
		prod = b;
	}
};
node merge(node a,node b){
	a.prod = (long long)a.prod * b.prod %mod;
	a.maxi = max(a.maxi,b.maxi);
	return a;
}
struct SegTree{
	vector<node> t;
	int n;
	void init(int size){
		n = size;
		t.assign(4*n,node(0,1));
	}
	void upd1(int v,int tl,int tr,int pos,int val){
		if(tl == tr){
			t[v].prod = val;
			return;
		}
		int tm = (tl + tr)/2;
		if(pos <= tm){
			upd1(v*2,tl,tm,pos,val);
		}
		else upd1(v*2+1,tm+1,tr,pos,val);
		t[v] = merge(t[v*2],t[v*2+1]);
	}
	void upd2(int v,int tl,int tr,int pos,int val){
		if(tl == tr){
			t[v].maxi = val;
			return;
		}
		int tm = (tl + tr)/2;
		if(pos <= tm){
			upd2(v*2,tl,tm,pos,val);
		}
		else upd2(v*2+1,tm+1,tr,pos,val);
		t[v] = merge(t[v*2],t[v*2+1]);
	}
	node get(int v,int tl,int tr,int l,int r){
		if(tr < l || r < tl){
			return node(0,1);
		}
		if(l <= tl && tr <= r){
			return t[v];
		}
		int tm = (tl + tr)/2;
		return merge(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
	}
	void upd1(int pos,int val){
		upd1(1,0,n-1,pos,val);
	}
	void upd2(int pos,int val){
		upd2(1,0,n-1,pos,val);
	}
	node get(int l,int r){
		return get(1,0,n-1,l,r);
	}
}tree;
const int BOUND = 1e9;
set<int> s;
int x[N],y[N];
int n;
int get_ans(){
	int l = 0;
	long long prod = 1;
	if(s.size()){
		auto it = prev(s.end());
		while(prod < BOUND){
			prod *= x[*it];
			if(prod >= BOUND){
				l = *it;
			}
			if(it == s.begin())break;
			it = prev(it);
		}
	}
	int tmp = l;
	int opt = l;
	long long val = 0;
	prod = 1;
	while(1){
		if(l != tmp){
			prod *= x[l];
		}
		auto foo = tree.get(l,n-1);
		if(prod * foo.maxi > val){
			val = prod * foo.maxi;
			opt = l;
		}
		if(s.upper_bound(l) == s.end())break;
		l = *s.upper_bound(l);
	}
	return (long long)tree.get(opt,n-1).maxi * tree.get(0,opt).prod % mod;
}
int init(int n_, int X[], int Y[]) {
	n = n_;
	tree.init(n);
	for(int i = 0;i<n;i++){
		x[i] = X[i];
		y[i] = Y[i];
		tree.upd1(i,x[i]);
		tree.upd2(i,y[i]);
		if(x[i] > 1){
			s.insert(i);
		}
	}
	return get_ans();
}

int updateX(int pos, int val) {	
	if(x[pos] > 1){
		s.erase(pos);
	}
	x[pos] = val;
	tree.upd1(pos,x[pos]);
	if(x[pos] > 1){
		s.insert(pos);
	}
	return get_ans();
}

int updateY(int pos, int val) {
	y[pos] = val;
	tree.upd2(pos,y[pos]);
	return get_ans();
}

Compilation message

horses.cpp: In function 'node merge(node, node)':
horses.cpp:15:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  a.prod = (long long)a.prod * b.prod %mod;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int get_ans()':
horses.cpp:104:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  104 |  return (long long)tree.get(opt,n-1).maxi * tree.get(0,opt).prod % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 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 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 1 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 1 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 1 ms 212 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
# 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 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 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 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 212 KB Output is correct
22 Correct 0 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 1 ms 340 KB Output is correct
27 Correct 3 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 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1524 ms 48368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 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 1 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 1 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 0 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 1 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 212 KB Output is correct
17 Correct 1 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 212 KB Output is correct
22 Correct 0 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 416 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 1 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 198 ms 23984 KB Output is correct
34 Correct 200 ms 23904 KB Output is correct
35 Correct 388 ms 47360 KB Output is correct
36 Correct 313 ms 47268 KB Output is correct
37 Correct 262 ms 23944 KB Output is correct
38 Correct 268 ms 35856 KB Output is correct
39 Correct 180 ms 23780 KB Output is correct
40 Correct 342 ms 47252 KB Output is correct
41 Correct 226 ms 23840 KB Output is correct
42 Correct 233 ms 23816 KB Output is correct
43 Correct 297 ms 47208 KB Output is correct
44 Correct 369 ms 47176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 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 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 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 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 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 1 ms 408 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 344 KB Output is correct
29 Correct 2 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 5 ms 340 KB Output is correct
33 Execution timed out 1588 ms 48132 KB Time limit exceeded
34 Halted 0 ms 0 KB -