답안 #590873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590873 2022-07-06T12:34:16 Z AlperenT 말 (IOI15_horses) C++17
100 / 100
846 ms 104984 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

const int N = 5e5 + 5, MOD = 1e9 + 7;

struct mint{
    int val;

    mint(long long a = 0) : val(a % MOD) {if(val < 0) val += MOD; }
    mint(long long a, long long b) {*this += a, *this /= b; }

    mint &operator += (const mint &b) {val += b.val; if(val >= MOD) val -= MOD; return *this; }
    mint &operator -= (const mint &b) {val -= b.val; if(val < 0) val += MOD; return *this; }
    mint &operator *= (const mint &b) {val = (1ll * val * b.val) % MOD; return *this; }
    mint &operator /= (const mint &b) {*this *= minv(b); return *this; }

    mint &operator ++ () {return *this += 1; }
    mint operator ++ (int) {mint tmp = *this; *this += 1; return tmp; }

    mint &operator -- () {return *this -= 1; }
    mint operator -- (int) {mint tmp = *this; *this -= 1; return tmp; }

    friend mint operator + (mint a, const mint &b) {return a += b; }
    friend mint operator - (mint a, const mint &b) {return a -= b; }
    friend mint operator - (const mint &a) {return 0 - a; }
    friend mint operator * (mint a, const mint &b) {return a *= b; }
    friend mint operator / (mint a, const mint &b) {return a /= b; }

    friend istream &operator >> (istream &is, mint &a) {long long b; cin >> b; a = b; return is; }
    friend ostream &operator << (ostream &os, const mint &a) {cout << a.val; return os; }

    mint mexp(mint a, long long b){
        mint c = 1;
        for(; b > 0; b /= 2, a *= a) if(b & 1) c *= a;
        return c;
    }

    mint minv(const mint &a) {return mexp(a, MOD - 2); }
};

int n, x[N], y[N];

struct SegTree{
	pair<long double, int> tree[N * 4];
	long double lazy[N * 4];

	void push(int v){
		if(lazy[v]){
			tree[v].first += lazy[v];

			if(v * 2 < N * 4) lazy[v * 2] += lazy[v], lazy[v * 2 + 1] += lazy[v];

			lazy[v] = 0;
		}
	}

	pair<long double, int> merge(pair<long double, int> a, pair<long double, int> b){
		return max(a, b);
	}

	void build(int v = 1, int l = 0, int r = n - 1){
		if(l == r) tree[v] = {0, l};
		else{
			int m = l + (r - l) / 2;

			build(v * 2, l, m);
			build(v * 2 + 1, m + 1, r);

			tree[v] = merge(tree[v * 2], tree[v * 2 + 1]);
		}
	}

	void update(int l, int r, long double val, int v = 1, int tl = 0, int tr = n - 1){
		if(l > r) return;
		else if(tl == l && tr == r) lazy[v] += val;
		else{
			push(v);

			int tm = tl + (tr - tl) / 2;

			update(l, min(r, tm), val, v * 2, tl, tm);
			update(max(l, tm + 1), r, val, v * 2 + 1, tm + 1, tr);

			push(v * 2), push(v * 2 + 1);

			tree[v] = merge(tree[v * 2], tree[v * 2 + 1]);
		}
	}

	int query(){
		push(1);
		return tree[1].second;
	}
};

SegTree sgt;

struct Fenwick{
	mint tree[N];

	Fenwick(){
		fill(tree, tree + N, mint(1));
	}

	mint query(int r){
		mint ans = 1;
		for(int i = r + 1; i > 0; i -= i & -i) ans *= tree[i];
		return ans;
	}

	void update(int pos, mint val){
		for(int i = pos + 1; i < N; i += i & -i) tree[i] *= val;
	}
};

Fenwick fw;

int init(int N_, int X[], int Y[]){
	n = N_;

	copy(X, X + n, x);
	copy(Y, Y + n, y);

	sgt.build();

	for(int i = 0; i < n; i++){
		sgt.update(i, n - 1, log(x[i]));
		sgt.update(i, i, log(y[i]));

		fw.update(i, x[i]);
	}

	int ans = sgt.query();

	return (fw.query(ans) * y[ans]).val;
}

int updateX(int pos, int val){	
	sgt.update(pos, n - 1, log(val) - log(x[pos]));
	fw.update(pos, mint(val) / x[pos]);

	x[pos] = val;

	int ans = sgt.query();

	return (fw.query(ans) * y[ans]).val;
}

int updateY(int pos, int val){
	sgt.update(pos, pos, log(val) - log(y[pos]));
	y[pos] = val;

	int ans = sgt.query();

	return (fw.query(ans) * y[ans]).val;;
}

Compilation message

horses.cpp: In constructor 'mint::mint(long long int)':
horses.cpp:11:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   11 |     mint(long long a = 0) : val(a % MOD) {if(val < 0) val += MOD; }
      |                                 ~~^~~~~
horses.cpp: In member function 'mint& mint::operator*=(const mint&)':
horses.cpp:16:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |     mint &operator *= (const mint &b) {val = (1ll * val * b.val) % MOD; return *this; }
      |                                              ~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 64840 KB Output is correct
2 Correct 24 ms 64860 KB Output is correct
3 Correct 24 ms 64852 KB Output is correct
4 Correct 24 ms 64856 KB Output is correct
5 Correct 26 ms 64868 KB Output is correct
6 Correct 29 ms 64800 KB Output is correct
7 Correct 27 ms 64860 KB Output is correct
8 Correct 24 ms 64860 KB Output is correct
9 Correct 24 ms 64872 KB Output is correct
10 Correct 24 ms 64852 KB Output is correct
11 Correct 26 ms 64928 KB Output is correct
12 Correct 25 ms 64808 KB Output is correct
13 Correct 28 ms 64876 KB Output is correct
14 Correct 28 ms 64852 KB Output is correct
15 Correct 24 ms 64820 KB Output is correct
16 Correct 26 ms 64876 KB Output is correct
17 Correct 26 ms 64844 KB Output is correct
18 Correct 30 ms 64812 KB Output is correct
19 Correct 24 ms 64852 KB Output is correct
20 Correct 23 ms 64828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 64852 KB Output is correct
2 Correct 28 ms 64900 KB Output is correct
3 Correct 29 ms 64844 KB Output is correct
4 Correct 29 ms 64836 KB Output is correct
5 Correct 26 ms 64776 KB Output is correct
6 Correct 26 ms 64852 KB Output is correct
7 Correct 24 ms 64792 KB Output is correct
8 Correct 24 ms 64852 KB Output is correct
9 Correct 25 ms 64860 KB Output is correct
10 Correct 24 ms 64816 KB Output is correct
11 Correct 31 ms 64860 KB Output is correct
12 Correct 30 ms 64848 KB Output is correct
13 Correct 26 ms 64852 KB Output is correct
14 Correct 28 ms 64832 KB Output is correct
15 Correct 25 ms 64908 KB Output is correct
16 Correct 27 ms 64852 KB Output is correct
17 Correct 25 ms 64844 KB Output is correct
18 Correct 24 ms 64852 KB Output is correct
19 Correct 25 ms 64784 KB Output is correct
20 Correct 28 ms 64884 KB Output is correct
21 Correct 24 ms 64880 KB Output is correct
22 Correct 26 ms 64824 KB Output is correct
23 Correct 28 ms 64964 KB Output is correct
24 Correct 27 ms 64852 KB Output is correct
25 Correct 31 ms 64872 KB Output is correct
26 Correct 29 ms 65056 KB Output is correct
27 Correct 25 ms 64880 KB Output is correct
28 Correct 28 ms 64980 KB Output is correct
29 Correct 26 ms 64852 KB Output is correct
30 Correct 27 ms 64872 KB Output is correct
31 Correct 26 ms 64992 KB Output is correct
32 Correct 26 ms 64864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 657 ms 104936 KB Output is correct
2 Correct 846 ms 104964 KB Output is correct
3 Correct 762 ms 104936 KB Output is correct
4 Correct 769 ms 104908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 64856 KB Output is correct
2 Correct 31 ms 64852 KB Output is correct
3 Correct 32 ms 64880 KB Output is correct
4 Correct 25 ms 64788 KB Output is correct
5 Correct 24 ms 64852 KB Output is correct
6 Correct 24 ms 64852 KB Output is correct
7 Correct 24 ms 64880 KB Output is correct
8 Correct 25 ms 64864 KB Output is correct
9 Correct 25 ms 64872 KB Output is correct
10 Correct 25 ms 64852 KB Output is correct
11 Correct 25 ms 64772 KB Output is correct
12 Correct 24 ms 64844 KB Output is correct
13 Correct 30 ms 64808 KB Output is correct
14 Correct 31 ms 64844 KB Output is correct
15 Correct 29 ms 64800 KB Output is correct
16 Correct 24 ms 64812 KB Output is correct
17 Correct 24 ms 64856 KB Output is correct
18 Correct 24 ms 64868 KB Output is correct
19 Correct 27 ms 64796 KB Output is correct
20 Correct 25 ms 64804 KB Output is correct
21 Correct 26 ms 64876 KB Output is correct
22 Correct 25 ms 64808 KB Output is correct
23 Correct 31 ms 64876 KB Output is correct
24 Correct 26 ms 64980 KB Output is correct
25 Correct 28 ms 64896 KB Output is correct
26 Correct 27 ms 64924 KB Output is correct
27 Correct 26 ms 64928 KB Output is correct
28 Correct 28 ms 64948 KB Output is correct
29 Correct 27 ms 64888 KB Output is correct
30 Correct 30 ms 64884 KB Output is correct
31 Correct 25 ms 64924 KB Output is correct
32 Correct 25 ms 64924 KB Output is correct
33 Correct 608 ms 104036 KB Output is correct
34 Correct 549 ms 104056 KB Output is correct
35 Correct 645 ms 104016 KB Output is correct
36 Correct 691 ms 104016 KB Output is correct
37 Correct 510 ms 101140 KB Output is correct
38 Correct 589 ms 104012 KB Output is correct
39 Correct 551 ms 89168 KB Output is correct
40 Correct 631 ms 104008 KB Output is correct
41 Correct 498 ms 89436 KB Output is correct
42 Correct 513 ms 89128 KB Output is correct
43 Correct 588 ms 104024 KB Output is correct
44 Correct 606 ms 103956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 64832 KB Output is correct
2 Correct 30 ms 64876 KB Output is correct
3 Correct 25 ms 64820 KB Output is correct
4 Correct 25 ms 64796 KB Output is correct
5 Correct 27 ms 64808 KB Output is correct
6 Correct 24 ms 64852 KB Output is correct
7 Correct 25 ms 64916 KB Output is correct
8 Correct 25 ms 64852 KB Output is correct
9 Correct 26 ms 64848 KB Output is correct
10 Correct 24 ms 64852 KB Output is correct
11 Correct 30 ms 64804 KB Output is correct
12 Correct 26 ms 64852 KB Output is correct
13 Correct 27 ms 64872 KB Output is correct
14 Correct 28 ms 64852 KB Output is correct
15 Correct 29 ms 64804 KB Output is correct
16 Correct 25 ms 64852 KB Output is correct
17 Correct 25 ms 64824 KB Output is correct
18 Correct 25 ms 64872 KB Output is correct
19 Correct 26 ms 64800 KB Output is correct
20 Correct 25 ms 64896 KB Output is correct
21 Correct 24 ms 64852 KB Output is correct
22 Correct 24 ms 64860 KB Output is correct
23 Correct 27 ms 64972 KB Output is correct
24 Correct 32 ms 64912 KB Output is correct
25 Correct 31 ms 65056 KB Output is correct
26 Correct 30 ms 64948 KB Output is correct
27 Correct 26 ms 64992 KB Output is correct
28 Correct 26 ms 64908 KB Output is correct
29 Correct 25 ms 64880 KB Output is correct
30 Correct 27 ms 64880 KB Output is correct
31 Correct 26 ms 64872 KB Output is correct
32 Correct 26 ms 64856 KB Output is correct
33 Correct 675 ms 104904 KB Output is correct
34 Correct 832 ms 104980 KB Output is correct
35 Correct 783 ms 104968 KB Output is correct
36 Correct 790 ms 104984 KB Output is correct
37 Correct 564 ms 104136 KB Output is correct
38 Correct 567 ms 104084 KB Output is correct
39 Correct 633 ms 104112 KB Output is correct
40 Correct 641 ms 104004 KB Output is correct
41 Correct 574 ms 101268 KB Output is correct
42 Correct 562 ms 104088 KB Output is correct
43 Correct 535 ms 89200 KB Output is correct
44 Correct 595 ms 104132 KB Output is correct
45 Correct 497 ms 89292 KB Output is correct
46 Correct 550 ms 89248 KB Output is correct
47 Correct 595 ms 103960 KB Output is correct
48 Correct 577 ms 103984 KB Output is correct
49 Correct 725 ms 104948 KB Output is correct
50 Correct 782 ms 104956 KB Output is correct
51 Correct 676 ms 104908 KB Output is correct
52 Correct 703 ms 104944 KB Output is correct
53 Correct 662 ms 104944 KB Output is correct
54 Correct 716 ms 104844 KB Output is correct
55 Correct 573 ms 89256 KB Output is correct
56 Correct 714 ms 104916 KB Output is correct
57 Correct 646 ms 90140 KB Output is correct
58 Correct 609 ms 90232 KB Output is correct
59 Correct 582 ms 103920 KB Output is correct