답안 #60146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60146 2018-07-23T18:00:57 Z Flugan42 말 (IOI15_horses) C++14
100 / 100
755 ms 177532 KB
//#include "horses.h"
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef long double Ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define per(i,a,b) for(ll i = a; i >= b; i--)
#define all(x) x.begin(),x.end()
#define inf 1000000000000000000
#define sz(x) (ll)(x).size()

const ll mod = 1000000007;

class segT {
private:
  vector<pair<Ld,ll> > tree;
	vector<Ld> lazy;
  vector<Ld> a;
  ll n;
  ll left(ll v) { return 2*v; }
  ll right(ll v) { return 2*v+1; }
  void build(ll v, ll l, ll r){
    if (l == r) tree[v] = make_pair(a[l],l);
    else {
      build(left(v),l,(l+r)/2);
      build(right(v),(l+r)/2+1,r);
      if (tree[left(v)].first > tree[right(v)].first) tree[v] = tree[left(v)];
      else tree[v] = tree[right(v)];
    }
  }
  pair<Ld,ll> rmq(ll v, ll l, ll r, ll i, ll j){
		if (lazy[v] != 0.0){
			tree[v].first += lazy[v];
			lazy[left(v)] += lazy[v];
			lazy[right(v)] += lazy[v];
			lazy[v] = 0.0;
		}
    if (l > j || r < i) return make_pair(-1,-1);
    if (i <= l && r <= j) return tree[v];
    else {
      pair<Ld,ll> p1 = rmq(left(v),l,(l+r)/2,i,j);
      pair<Ld,ll> p2 = rmq(right(v),(l+r)/2+1,r,i,j);
      if (p1.first == -1 && p2.first == -1) return make_pair(-1,-1);
      if (p1.first == -1) return p2;
      if (p2.first == -1) return p1;
      if (p1.first > p2.first) return p1;
      else return p2;
    }
  }
  void rangeadd(ll v, ll l, ll r, ll i, ll j, Ld val){
		if (lazy[v] != 0.0){
			tree[v].first += lazy[v];
			lazy[left(v)] += lazy[v];
			lazy[right(v)] += lazy[v];
			lazy[v] = 0.0;
		}
    if (l > j || r < i) return;
    if (i <= l && r <= j) {
			tree[v].first += val;
			lazy[left(v)] += val;
			lazy[right(v)] += val;
		}
    else {
      rangeadd(left(v), l, (l+r)/2, i, j, val);
      rangeadd(right(v), (l+r)/2+1, r, i, j, val);
      if (tree[left(v)].first > tree[right(v)].first) tree[v] = tree[left(v)];
      else tree[v] = tree[right(v)];
    }
  }
public:
	void build(vector<Ld> &_a){
		a = _a;
    n = sz(_a);
    tree.assign(4*n+10,make_pair(0.0,0));
		lazy.assign(8*n+10,0.0);
    build(1,0,n-1);
	}
  pair<Ld,ll> rmq(ll i, ll j) { return rmq(1,0,n-1,i,j); }
  void rangeadd(ll i, ll j, Ld val) { rangeadd(1,0,n-1,i,j,val); }
} ;


class segTp {
private:
  vi tree,a;
  ll n;
  ll left(ll v) { return 2*v; }
  ll right(ll v) { return 2*v+1; }
  void build(ll v, ll l, ll r){
    if (l == r) tree[v] = a[l]%mod;
    else {
      build(left(v),l,(l+r)/2);
      build(right(v),(l+r)/2+1,r);
      tree[v] = ((tree[left(v)]%mod)*(tree[right(v)]%mod))%mod;
    }
  }
  ll rmq(ll v, ll l, ll r, ll i, ll j){
    if (l > j || r < i) return -1;
    if (i <= l && r <= j) return (tree[v]%mod);
    else {
      ll p1 = rmq(left(v),l,(l+r)/2,i,j);
      ll p2 = rmq(right(v),(l+r)/2+1,r,i,j);
      if (p1 == -1 && p2 == -1) return -1;
      if (p1 == -1) return p2%mod;
      if (p2 == -1) return p1%mod;
      return ((p1%mod)*(p2%mod))%mod;
    }
  }
  void rangeprod(ll v, ll l, ll r, ll i, ll val){
    if (l > i || r < i) return;
    if (l == r && i == l) tree[v] = val%mod;
    else {
      rangeprod(left(v), l, (l+r)/2, i, val);
      rangeprod(right(v), (l+r)/2+1, r, i, val);
      tree[v] = ((tree[left(v)]%mod)*(tree[right(v)]%mod))%mod;
    }
  }
public:
  void build(vi &_a){
    a = _a;
    n = sz(_a);
    tree.assign(4*n+10,0);
    build(1,0,n-1);
  }
  ll rmq(ll i, ll j) { return rmq(1,0,n-1,i,j); }
  void rangeprod(ll i, ll val) { rangeprod(1,0,n-1,i,val); }
} ;

vi YY,XX;
vector<Ld> lnsum;
pair<Ld,ll> res;
segT myT;
segTp pT;
ll NN;

int init(int N, int X[], int Y[]) {
	lnsum.assign(N,0.0);
	lnsum[0] = log(Ld(X[0]));
	rep(i,0,N) YY.push_back(ll(Y[i]));
	rep(i,0,N) XX.push_back(ll(X[i]));
	rep(i,1,N){
		lnsum[i] = lnsum[i-1]+log(Ld(X[i]));
	}
	rep(i,0,N){
		lnsum[i] += log(Ld(Y[i]));
	}
	myT.build(lnsum);
	pT.build(XX);
	res = myT.rmq(0,N-1);
	NN = N;
	return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
}

int updateX(int pos, int val) {
	myT.rangeadd(pos,NN-1,log(Ld(val))-log(Ld(XX[pos])));
	XX[pos] = ll(val);
	pT.rangeprod(pos,val);
	res = myT.rmq(0,NN-1);
	return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
}

int updateY(int pos, int val) {
	myT.rangeadd(pos,pos,log(Ld(val))-log(Ld(YY[pos])));
	YY[pos] = ll(val);
	res = myT.rmq(0,NN-1);
	return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
}

/*
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");
	_outputFile = fopen("horses.out", "w");

	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();
	}

	fprintf(_outputFile,"%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) {
			fprintf(_outputFile,"%d\n",updateX(pos,val));
		} else if (type == 2) {
			fprintf(_outputFile,"%d\n",updateY(pos,val));
		}
	}

	return 0;
}
*/

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:156:58: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:164:58: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:171:58: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return ((pT.rmq(0,res.second)%mod)*(YY[res.second]%mod))%mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 3 ms 648 KB Output is correct
5 Correct 4 ms 648 KB Output is correct
6 Correct 3 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 2 ms 648 KB Output is correct
9 Correct 3 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 3 ms 676 KB Output is correct
13 Correct 3 ms 676 KB Output is correct
14 Correct 5 ms 676 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 4 ms 676 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
18 Correct 3 ms 676 KB Output is correct
19 Correct 3 ms 676 KB Output is correct
20 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 3 ms 676 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 720 KB Output is correct
5 Correct 3 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 720 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 3 ms 760 KB Output is correct
20 Correct 3 ms 760 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 2 ms 760 KB Output is correct
23 Correct 5 ms 1048 KB Output is correct
24 Correct 5 ms 1072 KB Output is correct
25 Correct 4 ms 1232 KB Output is correct
26 Correct 5 ms 1232 KB Output is correct
27 Correct 5 ms 1232 KB Output is correct
28 Correct 5 ms 1232 KB Output is correct
29 Correct 5 ms 1232 KB Output is correct
30 Correct 5 ms 1232 KB Output is correct
31 Correct 4 ms 1232 KB Output is correct
32 Correct 4 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 469 ms 175016 KB Output is correct
2 Correct 666 ms 175268 KB Output is correct
3 Correct 599 ms 175824 KB Output is correct
4 Correct 755 ms 175824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 175824 KB Output is correct
2 Correct 2 ms 175824 KB Output is correct
3 Correct 3 ms 175824 KB Output is correct
4 Correct 2 ms 175824 KB Output is correct
5 Correct 2 ms 175824 KB Output is correct
6 Correct 3 ms 175824 KB Output is correct
7 Correct 4 ms 175824 KB Output is correct
8 Correct 3 ms 175824 KB Output is correct
9 Correct 4 ms 175824 KB Output is correct
10 Correct 3 ms 175824 KB Output is correct
11 Correct 2 ms 175824 KB Output is correct
12 Correct 3 ms 175824 KB Output is correct
13 Correct 3 ms 175824 KB Output is correct
14 Correct 2 ms 175824 KB Output is correct
15 Correct 3 ms 175824 KB Output is correct
16 Correct 3 ms 175824 KB Output is correct
17 Correct 1 ms 175824 KB Output is correct
18 Correct 2 ms 175824 KB Output is correct
19 Correct 2 ms 175824 KB Output is correct
20 Correct 3 ms 175824 KB Output is correct
21 Correct 3 ms 175824 KB Output is correct
22 Correct 2 ms 175824 KB Output is correct
23 Correct 5 ms 175824 KB Output is correct
24 Correct 5 ms 175824 KB Output is correct
25 Correct 4 ms 175824 KB Output is correct
26 Correct 5 ms 175824 KB Output is correct
27 Correct 4 ms 175824 KB Output is correct
28 Correct 5 ms 175824 KB Output is correct
29 Correct 4 ms 175824 KB Output is correct
30 Correct 5 ms 175824 KB Output is correct
31 Correct 5 ms 175824 KB Output is correct
32 Correct 4 ms 175824 KB Output is correct
33 Correct 308 ms 175824 KB Output is correct
34 Correct 320 ms 175824 KB Output is correct
35 Correct 284 ms 175824 KB Output is correct
36 Correct 316 ms 175824 KB Output is correct
37 Correct 301 ms 175824 KB Output is correct
38 Correct 274 ms 175824 KB Output is correct
39 Correct 263 ms 175824 KB Output is correct
40 Correct 279 ms 175824 KB Output is correct
41 Correct 271 ms 175824 KB Output is correct
42 Correct 272 ms 175824 KB Output is correct
43 Correct 242 ms 175824 KB Output is correct
44 Correct 277 ms 175824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 175824 KB Output is correct
2 Correct 2 ms 175824 KB Output is correct
3 Correct 4 ms 175824 KB Output is correct
4 Correct 3 ms 175824 KB Output is correct
5 Correct 3 ms 175824 KB Output is correct
6 Correct 3 ms 175824 KB Output is correct
7 Correct 3 ms 175824 KB Output is correct
8 Correct 3 ms 175824 KB Output is correct
9 Correct 4 ms 175824 KB Output is correct
10 Correct 3 ms 175824 KB Output is correct
11 Correct 3 ms 175824 KB Output is correct
12 Correct 3 ms 175824 KB Output is correct
13 Correct 3 ms 175824 KB Output is correct
14 Correct 2 ms 175824 KB Output is correct
15 Correct 4 ms 175824 KB Output is correct
16 Correct 2 ms 175824 KB Output is correct
17 Correct 2 ms 175824 KB Output is correct
18 Correct 3 ms 175824 KB Output is correct
19 Correct 3 ms 175824 KB Output is correct
20 Correct 3 ms 175824 KB Output is correct
21 Correct 3 ms 175824 KB Output is correct
22 Correct 3 ms 175824 KB Output is correct
23 Correct 5 ms 175824 KB Output is correct
24 Correct 5 ms 175824 KB Output is correct
25 Correct 4 ms 175824 KB Output is correct
26 Correct 4 ms 175824 KB Output is correct
27 Correct 4 ms 175824 KB Output is correct
28 Correct 4 ms 175824 KB Output is correct
29 Correct 4 ms 175824 KB Output is correct
30 Correct 4 ms 175824 KB Output is correct
31 Correct 4 ms 175824 KB Output is correct
32 Correct 4 ms 175824 KB Output is correct
33 Correct 365 ms 176080 KB Output is correct
34 Correct 658 ms 176976 KB Output is correct
35 Correct 612 ms 176976 KB Output is correct
36 Correct 644 ms 176996 KB Output is correct
37 Correct 282 ms 176996 KB Output is correct
38 Correct 296 ms 176996 KB Output is correct
39 Correct 275 ms 176996 KB Output is correct
40 Correct 288 ms 176996 KB Output is correct
41 Correct 338 ms 176996 KB Output is correct
42 Correct 259 ms 176996 KB Output is correct
43 Correct 338 ms 176996 KB Output is correct
44 Correct 301 ms 176996 KB Output is correct
45 Correct 277 ms 176996 KB Output is correct
46 Correct 282 ms 176996 KB Output is correct
47 Correct 250 ms 176996 KB Output is correct
48 Correct 244 ms 176996 KB Output is correct
49 Correct 629 ms 177380 KB Output is correct
50 Correct 641 ms 177448 KB Output is correct
51 Correct 452 ms 177532 KB Output is correct
52 Correct 416 ms 177532 KB Output is correct
53 Correct 609 ms 177532 KB Output is correct
54 Correct 520 ms 177532 KB Output is correct
55 Correct 413 ms 177532 KB Output is correct
56 Correct 505 ms 177532 KB Output is correct
57 Correct 379 ms 177532 KB Output is correct
58 Correct 429 ms 177532 KB Output is correct
59 Correct 316 ms 177532 KB Output is correct