Submission #60126

# Submission time Handle Problem Language Result Execution time Memory
60126 2018-07-23T17:12:27 Z istlemin Horses (IOI15_horses) C++14
100 / 100
902 ms 224208 KB
#include "horses.h"
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

ll n;
vi x;
vi y;

ll mod = 1e9+7;

class OldNode{
public:
    ll val = 1;
    ll dn,up;
    OldNode *left;
    OldNode *right;

    OldNode(ll _dn,ll _up,vi &init){
		dn = _dn;
		up = _up;
        if(dn+1!=up){
            left = new OldNode(dn,(dn+up)/2,init);
            right = new OldNode((dn+up)/2,up,init);
            val = (left->val*right->val)%mod;
        } else {
            val = init[dn]%mod;
        }
    }

    ll update(ll a,ll v){
        if(dn>a||up<=a) return val;
        if(dn+1==up) {
			return val = v%mod;
        }
        return val = (left->update(a,v)*right->update(a,v))%mod;
    }

    ll query(ll a,ll b){
        if(dn>=b||up<=a) return 1;
        if(a<=dn&&up<=b) return val;
        return (left->query(a,b)*right->query(a,b))%mod;
    }
};

pair<long double,ll> op1(pair<long double,ll> a,long double b){
    return {a.first+b,a.second};
}

class Node{
public:
    pair<long double,ll> val = {0,0};
    long double toPush = 0;
    ll dn,up;
    Node *left;
    Node *right;

    Node(ll _dn,ll _up,vector<long double> &init){
		dn = _dn;
		up = _up;
        if(dn+1!=up){
            left = new Node(dn,(dn+up)/2,init);
            right = new Node((dn+up)/2,up,init);
            val = max(left->val,right->val);
        } else {
			val.second = dn;
            val.first = init[dn];
        }
    }

    void push(){
        if(dn+1==up) return;
        left->val=op1(left->val,toPush);
        right->val=op1(right->val,toPush);
        left->toPush+=toPush;
        right->toPush+=toPush;
        toPush = 0;
    }

    pair<long double,ll> update(ll a,ll b,long double v){
        if(dn>=b||up<=a) return val;
        if(a<=dn&&up<=b) {
            val=op1(val,v);
            toPush+=v;
			return val;
        }
        push();
        return val = max(left->update(a,b,v),right->update(a,b,v));
    }

    pair<long double,ll> query(ll a,ll b){
        if(dn>=b||up<=a) return {-1e30,0};
        if(a<=dn&&up<=b) return val;
        push();
        return max(left->query(a,b),right->query(a,b));
    }
};

Node *st;
OldNode *stMul;

ll getAns(){
    ll index = st->query(0,n).second;
    ll ans = (stMul->query(0,index+1)*y[index])%mod;
    //cout<<ans<<endl;
    return ans;
}

int init(int N, int X[], int Y[]) {
	n = N;
    x.resize(n,1);
    y.resize(n,1);
    rep(i,0,n) x[i] = X[i];
    rep(i,0,n) y[i] = Y[i];
    vector<long double> stD(n);
    stD[0] = log(x[0]);
    rep(i,1,n) stD[i] = log(x[i]) + stD[i-1];
    rep(i,0,n) stD[i] += log(y[i]);

	st = new Node(0,N,stD);
	stMul = new OldNode(0,N,x);

    rep(i,0,n){
        //updateX(i,X[i]);
        //updateY(i,Y[i]);

	}

	/*cout<<"#######"<<endl;
	rep(i,0,n) cout<<x[i]<<" ";
	cout<<endl;
	rep(i,0,n) cout<<y[i]<<" ";
	cout<<endl;
	rep(i,0,n) cout<<stMul->query(i,i+1)<<" ";
	cout<<endl;
	rep(i,0,n) cout<<st->query(i,i+1).first<<" ";
	cout<<endl;
	cout<<"#######"<<endl;*/

	return getAns();
}

int updateX(int pos, int val) {
    st->update(pos,n,-log((long double)(x[pos]))+log((long double)(val)));
    stMul->update(pos,val);
    x[pos] = val;
	return getAns();
}

int updateY(int pos, int val) {
    st->update(pos,pos+1,-log(y[pos])+log(val));
    y[pos] = val;
	return getAns();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:149:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return getAns();
         ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:156:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return getAns();
         ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:162:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return getAns();
         ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 496 KB Output is correct
8 Correct 2 ms 496 KB Output is correct
9 Correct 2 ms 552 KB Output is correct
10 Correct 3 ms 552 KB Output is correct
11 Correct 3 ms 552 KB Output is correct
12 Correct 2 ms 552 KB Output is correct
13 Correct 2 ms 552 KB Output is correct
14 Correct 2 ms 552 KB Output is correct
15 Correct 3 ms 552 KB Output is correct
16 Correct 2 ms 552 KB Output is correct
17 Correct 2 ms 552 KB Output is correct
18 Correct 3 ms 552 KB Output is correct
19 Correct 3 ms 576 KB Output is correct
20 Correct 3 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 576 KB Output is correct
2 Correct 3 ms 576 KB Output is correct
3 Correct 0 ms 576 KB Output is correct
4 Correct 3 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 3 ms 576 KB Output is correct
10 Correct 3 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 3 ms 576 KB Output is correct
14 Correct 3 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 4 ms 576 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 2 ms 576 KB Output is correct
19 Correct 3 ms 576 KB Output is correct
20 Correct 2 ms 576 KB Output is correct
21 Correct 2 ms 576 KB Output is correct
22 Correct 2 ms 576 KB Output is correct
23 Correct 4 ms 876 KB Output is correct
24 Correct 5 ms 876 KB Output is correct
25 Correct 4 ms 944 KB Output is correct
26 Correct 4 ms 944 KB Output is correct
27 Correct 5 ms 944 KB Output is correct
28 Correct 5 ms 980 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 5 ms 980 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 422 ms 161200 KB Output is correct
2 Correct 762 ms 161200 KB Output is correct
3 Correct 683 ms 161200 KB Output is correct
4 Correct 902 ms 161200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 161200 KB Output is correct
2 Correct 3 ms 161200 KB Output is correct
3 Correct 3 ms 161200 KB Output is correct
4 Correct 3 ms 161200 KB Output is correct
5 Correct 3 ms 161200 KB Output is correct
6 Correct 3 ms 161200 KB Output is correct
7 Correct 2 ms 161200 KB Output is correct
8 Correct 3 ms 161200 KB Output is correct
9 Correct 3 ms 161200 KB Output is correct
10 Correct 3 ms 161200 KB Output is correct
11 Correct 3 ms 161200 KB Output is correct
12 Correct 3 ms 161200 KB Output is correct
13 Correct 3 ms 161200 KB Output is correct
14 Correct 2 ms 161200 KB Output is correct
15 Correct 4 ms 161200 KB Output is correct
16 Correct 3 ms 161200 KB Output is correct
17 Correct 3 ms 161200 KB Output is correct
18 Correct 3 ms 161200 KB Output is correct
19 Correct 3 ms 161200 KB Output is correct
20 Correct 3 ms 161200 KB Output is correct
21 Correct 3 ms 161200 KB Output is correct
22 Correct 2 ms 161200 KB Output is correct
23 Correct 5 ms 161200 KB Output is correct
24 Correct 5 ms 161200 KB Output is correct
25 Correct 5 ms 161200 KB Output is correct
26 Correct 4 ms 161200 KB Output is correct
27 Correct 4 ms 161200 KB Output is correct
28 Correct 5 ms 161200 KB Output is correct
29 Correct 5 ms 161200 KB Output is correct
30 Correct 5 ms 161200 KB Output is correct
31 Correct 4 ms 161200 KB Output is correct
32 Correct 4 ms 161200 KB Output is correct
33 Correct 298 ms 161200 KB Output is correct
34 Correct 298 ms 161200 KB Output is correct
35 Correct 342 ms 161200 KB Output is correct
36 Correct 365 ms 161200 KB Output is correct
37 Correct 300 ms 161200 KB Output is correct
38 Correct 347 ms 161268 KB Output is correct
39 Correct 239 ms 161268 KB Output is correct
40 Correct 327 ms 161268 KB Output is correct
41 Correct 251 ms 161268 KB Output is correct
42 Correct 291 ms 161268 KB Output is correct
43 Correct 291 ms 161268 KB Output is correct
44 Correct 305 ms 161268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 161268 KB Output is correct
2 Correct 2 ms 161268 KB Output is correct
3 Correct 3 ms 161268 KB Output is correct
4 Correct 2 ms 161268 KB Output is correct
5 Correct 3 ms 161268 KB Output is correct
6 Correct 3 ms 161268 KB Output is correct
7 Correct 3 ms 161268 KB Output is correct
8 Correct 2 ms 161268 KB Output is correct
9 Correct 3 ms 161268 KB Output is correct
10 Correct 3 ms 161268 KB Output is correct
11 Correct 2 ms 161268 KB Output is correct
12 Correct 2 ms 161268 KB Output is correct
13 Correct 2 ms 161268 KB Output is correct
14 Correct 3 ms 161268 KB Output is correct
15 Correct 3 ms 161268 KB Output is correct
16 Correct 2 ms 161268 KB Output is correct
17 Correct 2 ms 161268 KB Output is correct
18 Correct 3 ms 161268 KB Output is correct
19 Correct 3 ms 161268 KB Output is correct
20 Correct 3 ms 161268 KB Output is correct
21 Correct 3 ms 161268 KB Output is correct
22 Correct 2 ms 161268 KB Output is correct
23 Correct 5 ms 161268 KB Output is correct
24 Correct 5 ms 161268 KB Output is correct
25 Correct 5 ms 161268 KB Output is correct
26 Correct 5 ms 161268 KB Output is correct
27 Correct 5 ms 161268 KB Output is correct
28 Correct 5 ms 161268 KB Output is correct
29 Correct 4 ms 161268 KB Output is correct
30 Correct 5 ms 161268 KB Output is correct
31 Correct 3 ms 161268 KB Output is correct
32 Correct 6 ms 161268 KB Output is correct
33 Correct 389 ms 161268 KB Output is correct
34 Correct 750 ms 161268 KB Output is correct
35 Correct 736 ms 161268 KB Output is correct
36 Correct 753 ms 161268 KB Output is correct
37 Correct 302 ms 161268 KB Output is correct
38 Correct 303 ms 161268 KB Output is correct
39 Correct 376 ms 161268 KB Output is correct
40 Correct 320 ms 161268 KB Output is correct
41 Correct 326 ms 161268 KB Output is correct
42 Correct 313 ms 161268 KB Output is correct
43 Correct 302 ms 161268 KB Output is correct
44 Correct 317 ms 161268 KB Output is correct
45 Correct 233 ms 161268 KB Output is correct
46 Correct 299 ms 161268 KB Output is correct
47 Correct 293 ms 161268 KB Output is correct
48 Correct 288 ms 161268 KB Output is correct
49 Correct 830 ms 165256 KB Output is correct
50 Correct 687 ms 170232 KB Output is correct
51 Correct 504 ms 182264 KB Output is correct
52 Correct 479 ms 194216 KB Output is correct
53 Correct 664 ms 196616 KB Output is correct
54 Correct 544 ms 200924 KB Output is correct
55 Correct 384 ms 204160 KB Output is correct
56 Correct 532 ms 210964 KB Output is correct
57 Correct 443 ms 213928 KB Output is correct
58 Correct 478 ms 216680 KB Output is correct
59 Correct 305 ms 224208 KB Output is correct