Submission #833868

# Submission time Handle Problem Language Result Execution time Memory
833868 2023-08-22T09:15:06 Z Victor Horses (IOI15_horses) C++17
54 / 100
321 ms 138248 KB
#include "horses.h"

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const ll INF = 1'000'000'007;

struct Node {
    ll lo,hi,id;
    double log_sum=0,val,madd=0;
    Node *l,*r;
    Node(const vll&x, const vll&y, double add, ll L,ll R) : lo(L), hi(R) {
        if(hi-lo==1) {
            log_sum=logf64(x[lo])+add;
            val=log_sum+logf64(y[lo]);
            id=lo;

        } else {
            ll mid=(lo+hi)/2;
            l=new Node(x,y,add,lo,mid);
            r=new Node(x,y,l->log_sum,mid,hi);
            log_sum=r->log_sum;
            tie(val,id)=max(pair<double,ll>(l->val,l->id),pair<double,ll>(r->val,r->id));
        }
        //cout<<"lo = "<<lo<<" hi = "<<hi<<" log_sum = "<<log_sum<<" add = "<<add<<" val = "<<val<<endl;
    }


    void updateX(ll pos, double v) { // v is differnce between new x[pos] - prev x[pos]
        if(hi<=pos) return;
        if(pos<=lo) {
            madd+=v;
            log_sum+=v;
            val+=v;
            return;
        }

        push();
        l->updateX(pos,v);
        r->updateX(pos,v);
        tie(val,id)=max(pair<double,ll>(l->val,l->id),pair<double,ll>(r->val,r->id));
    }

    void updateY(ll pos, ll v) { // v is new y[pos]
        if(pos<lo||hi<=pos) return;
        if(hi-lo==1) {
            val=log_sum+logf64(v);
            return;
        }

        push();
        l->updateY(pos,v);
        r->updateY(pos,v);
        tie(val,id)=max(pair<double,ll>(l->val,l->id),pair<double,ll>(r->val,r->id));
    }

    void push() {
        if(madd!=0) {
            l->updateX(0,madd);
            r->updateX(0,madd);
            madd=0;
        }
    }
};

struct Prod {
    ll lo,hi,prod;
    Prod *l,*r;
    Prod(const vll&x,ll L,ll R) : lo(L), hi(R) {
        if(hi-lo==1) {
            prod=x[lo];

        } else {
            ll mid=(lo+hi)/2;
            l=new Prod(x,lo,mid);
            r=new Prod(x,mid,hi);
            prod=l->prod*r->prod%INF;
        }
    }

    ll query(ll R) {
        if(R<=lo) return 1;
        if(hi<=R) return prod;
        return l->query(R)*r->query(R)%INF;
    }

    void updateX(ll pos,ll v) { // v is new x[pos]
        if(pos<lo||hi<=pos) return; 
        if(hi-lo==1) {
            prod=v;
            return;
        }

        l->updateX(pos,v);
        r->updateX(pos,v);
        prod=l->prod*r->prod%INF;
    }
};

vll x,y;
Node *segtree;
Prod *prodseg;

int init(int N, int X[], int Y[]) {
    rep(i,0,N) {
        assert(X[i]&&Y[i]);
        x.pb(X[i]);
        y.pb(Y[i]);
    }

    segtree=new Node(x,y,0,0,N);
    prodseg=new Prod(x,0,N);

    ll id=segtree->id;
    return prodseg->query(id+1)*y[id]%INF;
}

int updateX(int pos, int val) {
    assert(val);
    double diff=logf64(val)-logf64(x[pos]);
    x[pos]=val;
    segtree->updateX(pos,diff);
    prodseg->updateX(pos,val);
    ll id=segtree->id;
    return prodseg->query(id+1)*y[id]%INF;
}

int updateY(int pos, int val) {
    assert(val);
    y[pos]=val;
    segtree->updateY(pos,val);
    ll id=segtree->id;
    return prodseg->query(id+1)*y[id]%INF;
}
/*
#include "horses.h"
#include <stdio.h>
#include <stdlib.h>

static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}

static inline int _readInt() {
    int c, X, s;
    c = _read();
    while (c <= 32) c = _read();
    X = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        X *= 10;
        X += c - '0';
        c = _read();
    }
    if (s < 0) X = -X;
    return X;
}


int main() {
	_inputFile = fopen("horses.in", "rb");
	
	int N; N = _readInt();

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		X[i] = _readInt();
	}

	for (int i = 0; i < N; i++) {
		Y[i] = _readInt();
	}	

	printf("%d\n",init(N,X,Y));

	int M; M = _readInt();

	for (int i = 0; i < M; i++) {
		int type; type = _readInt();
		int pos; pos = _readInt();
		int val; val = _readInt(); 

		if (type == 1) {
			printf("%d\n",updateX(pos,val));
		} else if (type == 2) {
			printf("%d\n",updateY(pos,val));
		}
	}

	return 0;
}*/

Compilation message

horses.cpp: In constructor 'Node::Node(const vll&, const vll&, double, ll, ll)':
horses.cpp:27:33: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
   27 |             log_sum=logf64(x[lo])+add;
      |                                 ^
horses.cpp:28:37: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
   28 |             val=log_sum+logf64(y[lo]);
      |                                     ^
horses.cpp: In member function 'void Node::updateY(ll, ll)':
horses.cpp:60:32: warning: conversion from 'll' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
   60 |             val=log_sum+logf64(v);
      |                                ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:128:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  128 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:133:42: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
  133 |     double diff=logf64(val)-logf64(x[pos]);
      |                                          ^
horses.cpp:138:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  138 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:146:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  146 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 1 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 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 1 ms 212 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 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 0 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 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 516 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 138224 KB Output is correct
2 Correct 279 ms 138232 KB Output is correct
3 Correct 281 ms 138248 KB Output is correct
4 Correct 312 ms 138188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 260 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
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 125 ms 137276 KB Output is correct
34 Correct 132 ms 137364 KB Output is correct
35 Correct 143 ms 137336 KB Output is correct
36 Correct 127 ms 137328 KB Output is correct
37 Correct 110 ms 137356 KB Output is correct
38 Correct 155 ms 137380 KB Output is correct
39 Correct 101 ms 137244 KB Output is correct
40 Correct 114 ms 137396 KB Output is correct
41 Correct 96 ms 137272 KB Output is correct
42 Correct 98 ms 137380 KB Output is correct
43 Correct 113 ms 137256 KB Output is correct
44 Incorrect 114 ms 137180 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 1 ms 212 KB Output is correct
7 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 252 KB Output is correct
16 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 576 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 145 ms 138212 KB Output is correct
34 Correct 284 ms 138168 KB Output is correct
35 Correct 268 ms 138248 KB Output is correct
36 Correct 321 ms 138228 KB Output is correct
37 Correct 152 ms 137408 KB Output is correct
38 Correct 128 ms 137332 KB Output is correct
39 Correct 142 ms 137276 KB Output is correct
40 Correct 134 ms 137316 KB Output is correct
41 Correct 143 ms 137304 KB Output is correct
42 Correct 112 ms 137320 KB Output is correct
43 Correct 104 ms 137296 KB Output is correct
44 Correct 138 ms 137364 KB Output is correct
45 Correct 97 ms 137328 KB Output is correct
46 Correct 103 ms 137372 KB Output is correct
47 Correct 116 ms 137272 KB Output is correct
48 Incorrect 118 ms 137268 KB Output isn't correct
49 Halted 0 ms 0 KB -