답안 #833861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833861 2023-08-22T09:09:42 Z Victor 말 (IOI15_horses) C++17
54 / 100
309 ms 138340 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) {
        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) {
    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) {
    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:127:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  127 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:131: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]
  131 |     double diff=logf64(val)-logf64(x[pos]);
      |                                          ^
horses.cpp:136:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  136 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:143:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  143 |     return prodseg->query(id+1)*y[id]%INF;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 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 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 260 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 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 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 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 336 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 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 2 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 138212 KB Output is correct
2 Correct 284 ms 138276 KB Output is correct
3 Correct 252 ms 138176 KB Output is correct
4 Correct 309 ms 138340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 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 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 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 1 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 124 ms 137348 KB Output is correct
34 Correct 124 ms 137380 KB Output is correct
35 Correct 131 ms 137380 KB Output is correct
36 Correct 131 ms 137380 KB Output is correct
37 Correct 113 ms 137296 KB Output is correct
38 Correct 110 ms 137328 KB Output is correct
39 Correct 100 ms 137244 KB Output is correct
40 Correct 117 ms 137380 KB Output is correct
41 Correct 100 ms 137620 KB Output is correct
42 Correct 99 ms 137380 KB Output is correct
43 Correct 113 ms 137252 KB Output is correct
44 Incorrect 123 ms 137252 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 1 ms 260 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 212 KB Output is correct
16 Correct 1 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 1 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 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 592 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 137 ms 138220 KB Output is correct
34 Correct 279 ms 138272 KB Output is correct
35 Correct 256 ms 138252 KB Output is correct
36 Correct 305 ms 138212 KB Output is correct
37 Correct 170 ms 137308 KB Output is correct
38 Correct 125 ms 137380 KB Output is correct
39 Correct 147 ms 137340 KB Output is correct
40 Correct 134 ms 137380 KB Output is correct
41 Correct 119 ms 137332 KB Output is correct
42 Correct 114 ms 137380 KB Output is correct
43 Correct 104 ms 137252 KB Output is correct
44 Correct 121 ms 137336 KB Output is correct
45 Correct 104 ms 137344 KB Output is correct
46 Correct 101 ms 137380 KB Output is correct
47 Correct 142 ms 137236 KB Output is correct
48 Incorrect 118 ms 137244 KB Output isn't correct
49 Halted 0 ms 0 KB -