Submission #245872

# Submission time Handle Problem Language Result Execution time Memory
245872 2020-07-07T16:08:47 Z Evirir Horses (IOI15_horses) C++17
100 / 100
1075 ms 82040 KB
#include "horses.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;

ll add(ll a,ll b)
{
	a+=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll inverse(ll a)
{
	return pw(a,MOD-2);
}

struct Node{
	ll p, mx;
};

class PointSegmentTree{
private:
	int size_;
	vector<Node> v;
	
	void update(int p, ll val, int type, int k, int l, int r)
	{
		if(p < l || r < p) return;
		if(l == r){
			if(type==0) v[k].p=val;	//modification
			else v[k].mx=val;
			return;
		}
		int mid = (l+r)>>1;
		update(p, val, type, k*2, l, mid);
		update(p, val, type, k*2+1, mid+1, r);
		v[k] = merge(v[k*2], v[k*2+1]);
	}
	
	Node query(int s, int e, int k, int l, int r)
	{
		if(e < l || r < s) return Node{1,1}; //dummy value
		if(s <= l && r <= e) return v[k];
		int mid = (l+r)>>1;
		Node lc = query(s, e, k*2, l, mid);
		Node rc = query(s, e, k*2+1, mid+1, r);
		return merge(lc, rc);
	}
	
public:
	PointSegmentTree(): v(vector<Node>()) {}
	PointSegmentTree(int n){
		for(size_=1;size_<n;) size_<<=1;
		v.resize(size_*4);
	}
	//void reset(){}
	inline Node merge(const Node &x, const Node &y){
		return Node{mult(x.p, y.p), max(x.mx, y.mx)};
	}
	inline void update(int p, ll val, int type){
		update(p, val, type, 1, 0, size_-1);
	}
	inline Node query(int l, int r){
		return query(l, r, 1, 0, size_-1);
	}
};

bool DEBUG = 0;
const int MAXN = 500005;

int n;
ll x[MAXN],y[MAXN];
set<int> s;
PointSegmentTree st;

ll query()
{
	ll pro=-1;
	ll best=n-1, besty=1;
	int pre=n;
	for(auto it=s.rbegin();it!=s.rend();it++)
	{
		int i=*it;
		//cerr<<"i="<<i<<'\n';
		
		//cerr<<"pro="<<pro<<'\n';
		
		ll tmpy=st.query(i,pre-1).mx;
		//cerr<<"tmpy="<<tmpy<<'\n';
		if(tmpy > pro){
			best=i;
			pro=tmpy;
			besty=tmpy;
			//cerr<<"pro="<<pro<<" best="<<best<<" besty="<<besty<<" pro="<<pro<<'\n';
		}
		pro*=x[i];
		if(pro>1e9) break;
		pre=i;
	}
	
	ll p=st.query(0,best).p;
	//cerr<<"p="<<p<<" besty="<<besty<<'\n'<<'\n';
	return mult(p, besty);
}

int init(int N, int X[], int Y[])
{
	n=N;
	st=PointSegmentTree(n);
	
	for(int i=0;i<n;i++){
		x[i]=X[i], y[i]=Y[i];
		if(x[i]>1 || i==0) s.insert(i);
	}
	
	//cerr<<"s.size="<<s.size()<<"\n\n";
	
	forn(i,0,n){
		//cerr<<"x["<<i<<"]="<<x[i]<<" y["<<i<<"]="<<y[i]<<'\n';
		st.update(i,x[i],0);
		st.update(i,y[i],1);
	}
	
	return query();
}

int updateX(int pos, int val)
{	
	if(s.find(pos)!=s.end()) s.erase(pos);
	x[pos] = val;
	if(val>1 || pos==0) s.insert(pos);
	st.update(pos,val,0);
	return query();
}

int updateY(int pos, int val)
{
	y[pos] = val;
	st.update(pos,val,1);
	return query();
}

Compilation message

horses.cpp: In function 'll query()':
horses.cpp:139:10: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
   if(pro>1e9) break;
          ^~~
horses.cpp:143:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  ll p=st.query(0,best).p;
                      ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:166:14: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return query();
         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:175:14: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return query();
         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:182:14: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return query();
         ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 8 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 927 ms 70992 KB Output is correct
2 Correct 611 ms 75492 KB Output is correct
3 Correct 654 ms 73208 KB Output is correct
4 Correct 659 ms 75640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 432 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 8 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 7 ms 512 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 291 ms 45176 KB Output is correct
34 Correct 287 ms 45176 KB Output is correct
35 Correct 430 ms 68440 KB Output is correct
36 Correct 425 ms 68472 KB Output is correct
37 Correct 351 ms 45244 KB Output is correct
38 Correct 348 ms 60024 KB Output is correct
39 Correct 286 ms 46976 KB Output is correct
40 Correct 410 ms 74360 KB Output is correct
41 Correct 315 ms 47096 KB Output is correct
42 Correct 336 ms 47096 KB Output is correct
43 Correct 423 ms 74872 KB Output is correct
44 Correct 407 ms 74872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 8 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 927 ms 71032 KB Output is correct
34 Correct 611 ms 82040 KB Output is correct
35 Correct 623 ms 73208 KB Output is correct
36 Correct 657 ms 77048 KB Output is correct
37 Correct 310 ms 49012 KB Output is correct
38 Correct 297 ms 49124 KB Output is correct
39 Correct 451 ms 79328 KB Output is correct
40 Correct 429 ms 79352 KB Output is correct
41 Correct 355 ms 47216 KB Output is correct
42 Correct 363 ms 60024 KB Output is correct
43 Correct 329 ms 46968 KB Output is correct
44 Correct 473 ms 74360 KB Output is correct
45 Correct 318 ms 47096 KB Output is correct
46 Correct 324 ms 47096 KB Output is correct
47 Correct 410 ms 74872 KB Output is correct
48 Correct 404 ms 74744 KB Output is correct
49 Correct 443 ms 52216 KB Output is correct
50 Correct 407 ms 52216 KB Output is correct
51 Correct 610 ms 81272 KB Output is correct
52 Correct 498 ms 80760 KB Output is correct
53 Correct 1075 ms 50424 KB Output is correct
54 Correct 537 ms 63864 KB Output is correct
55 Correct 454 ms 48120 KB Output is correct
56 Correct 525 ms 76280 KB Output is correct
57 Correct 703 ms 48816 KB Output is correct
58 Correct 828 ms 49528 KB Output is correct
59 Correct 405 ms 74872 KB Output is correct