답안 #1013657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013657 2024-07-03T18:37:14 Z Mardonbekhazratov 말 (IOI15_horses) C++17
100 / 100
320 ms 48520 KB
#include "horses.h"
#include<algorithm>
#include<vector>
#include<iostream>
#include<set>
const long long INFLL=1e18;
const int INF=1e9;
const int MOD=1e9+7;

using namespace std;

struct SegTree{
    int N;
    const int NEU=0;
    vector<int>tree;

    int merge(int a,int b){
        return max(a,b);
    }

    void build(vector<int>&a){
        N=1;
        int n=a.size();
        while(N<n) N<<=1;

        tree.assign(N<<1,NEU);
        for(int i=0;i<n;i++) tree[i+N]=a[i];
        for(int i=N-1;i>0;i--) tree[i]=merge(tree[i<<1],tree[i<<1|1]);
    }

    void update(int v,int l,int r,int id,int x){
        if(l>id || id>=r) return;
        if(r-l==1){
            tree[v]=x;
            return;
        }

        int mid=(l+r)>>1;
        update(v<<1,l,mid,id,x);
        update(v<<1|1,mid,r,id,x);

        tree[v]=merge(tree[v<<1],tree[v<<1|1]);
    }

    void update(int id,int x){
        return update(1,0,N,id,x);
    }

    int get(int v,int l,int r,int ql,int qr){
        if(l>=qr || ql>=r) return NEU;
        if(l>=ql && qr>=r) return tree[v];

        int mid=(l+r)>>1;
        int a=get(v<<1,l,mid,ql,qr);
        int b=get(v<<1|1,mid,r,ql,qr);
        return merge(a,b);
    }

    int get(int l,int r){
		if(r<=l) return 0;
        return get(1,0,N,l,r);
    }
};

int inv(int x){
	return x>1 ? MOD-(long long)(MOD/x)*inv(MOD%x)%MOD : x;
}

int n;
vector<int>x,y;
set<int>p;

SegTree S;
long long pref;

int get(){
	long long ans=1;
	long long pr=pref;
	int last=n;
	for(int j:p){
		int i=n-j;
		ans=max(ans,1LL*S.get(i,last));
		last=i;
		if(ans>=INF){
			ans%=MOD;
			return pr*ans%MOD;
		}
		ans*=x[i];
		pr=pr*inv(x[i])%MOD;
	}
	return max(ans*pr,1LL*S.get(0,last))%MOD;
}

int init(int N, int X[], int Y[]) {
	n=N;
	pref=1;
	x.resize(n);
	y.resize(n);
	for(int i=0;i<n;i++){
		x[i]=X[i],y[i]=Y[i];
		pref=pref*x[i]%MOD;
		if(x[i]>1) p.insert(n-i);
	}
	S.build(y);
	return get();
}


int updateX(int pos, int val) {	
	if(x[pos]>1) p.erase(n-pos);
	pref=pref*inv(x[pos])%MOD*val%MOD;
	x[pos]=val;
	if(x[pos]>1) p.insert(n-pos);
	return get();
}

int updateY(int pos, int val) {
	S.update(pos,val);
	return get();
}

Compilation message

horses.cpp: In member function 'void SegTree::build(std::vector<int>&)':
horses.cpp:23:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   23 |         int n=a.size();
      |               ~~~~~~^~
horses.cpp: In function 'int inv(int)':
horses.cpp:66:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 |  return x>1 ? MOD-(long long)(MOD/x)*inv(MOD%x)%MOD : x;
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get()':
horses.cpp:86:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |    return pr*ans%MOD;
      |           ~~~~~~^~~~
horses.cpp:91:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |  return max(ans*pr,1LL*S.get(0,last))%MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 408 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 436 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 2 ms 484 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 39624 KB Output is correct
2 Correct 215 ms 43692 KB Output is correct
3 Correct 240 ms 38992 KB Output is correct
4 Correct 245 ms 41228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 31 ms 15816 KB Output is correct
34 Correct 29 ms 15856 KB Output is correct
35 Correct 147 ms 44232 KB Output is correct
36 Correct 142 ms 44248 KB Output is correct
37 Correct 51 ms 14652 KB Output is correct
38 Correct 66 ms 26960 KB Output is correct
39 Correct 22 ms 14428 KB Output is correct
40 Correct 137 ms 41808 KB Output is correct
41 Correct 41 ms 14472 KB Output is correct
42 Correct 35 ms 14424 KB Output is correct
43 Correct 116 ms 42180 KB Output is correct
44 Correct 120 ms 42164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 281 ms 40300 KB Output is correct
34 Correct 210 ms 46764 KB Output is correct
35 Correct 219 ms 39704 KB Output is correct
36 Correct 221 ms 42752 KB Output is correct
37 Correct 36 ms 15916 KB Output is correct
38 Correct 28 ms 15792 KB Output is correct
39 Correct 137 ms 44388 KB Output is correct
40 Correct 136 ms 44220 KB Output is correct
41 Correct 47 ms 14424 KB Output is correct
42 Correct 78 ms 26952 KB Output is correct
43 Correct 19 ms 14416 KB Output is correct
44 Correct 126 ms 41816 KB Output is correct
45 Correct 40 ms 14416 KB Output is correct
46 Correct 34 ms 14480 KB Output is correct
47 Correct 117 ms 42028 KB Output is correct
48 Correct 142 ms 42068 KB Output is correct
49 Correct 94 ms 19460 KB Output is correct
50 Correct 87 ms 19408 KB Output is correct
51 Correct 189 ms 48520 KB Output is correct
52 Correct 152 ms 48212 KB Output is correct
53 Correct 280 ms 17708 KB Output is correct
54 Correct 137 ms 31324 KB Output is correct
55 Correct 51 ms 15440 KB Output is correct
56 Correct 229 ms 43468 KB Output is correct
57 Correct 157 ms 15952 KB Output is correct
58 Correct 178 ms 16724 KB Output is correct
59 Correct 112 ms 42188 KB Output is correct