답안 #210912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210912 2020-03-19T02:08:20 Z autumn_eel 말 (IOI15_horses) C++14
100 / 100
436 ms 57208 KB
#include "horses.h"
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

const int MOD=1000000007;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

struct BIT{
	vector<ll>bit;
	BIT(){}
	BIT(int n){
		n=n+10;
		bit=vector<ll>(n,1);
	}
	void add(int k,ll x){
		k++;
		while(k<bit.size()){
			(bit[k]*=x)%=MOD;
			k+=k&-k;
		}
	}
	ll sum(int k){//[0,k)
		ll res=1;
		while(k){
			(res*=bit[k])%=MOD;
			k-=k&-k;
		}
		return res;
	}
}bit;

struct Segtree{
	int N;
	vector<int>dat;
	Segtree(){}
	Segtree(int n){
		N=1;while(N<n)N<<=1;
		dat=vector<int>(2*N);
	}
	void update(int k,int x){
		k+=N;dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=max(dat[k*2],dat[k*2+1]);
		}
	}
	int query(int l,int r){
		int res=0;
		for(l+=N,r+=N;l<r;l>>=1,r>>=1){
			if(l&1)res=max(res,dat[l++]);
			if(r&1)res=max(res,dat[--r]);
		}
		return res;
	}
}seg;

int n;
ll x[600000],y[600000];
set<int>se;


ll calc(){
	if(se.empty())return seg.query(0,n)%MOD;
	ll res=0;
	ll M=1;
	auto s=--se.end();
	while(1){
		M*=x[*s];
		if(M>1e9||s==se.begin())break;
		s--;
	}
	__int128 Max=0,cur=1;
	for(auto it=s;it!=se.end();it++){
		cur*=x[*it];
		ll d=seg.query(*it,(it==--se.end()?n:*next(it)));
		Max=max(Max,cur*d);
	}
	Max*=bit.sum(*s);
	Max=max(Max,(__int128)seg.query(0,*se.begin()));
	return Max%MOD;
}

int init(int N, int X[], int Y[]) {
	n=N;
	bit=BIT(n);seg=Segtree(n);
	rep(i,n){
		x[i]=X[i],y[i]=Y[i];
		bit.add(i,x[i]);
		seg.update(i,y[i]);
		if(x[i]>1)se.insert(i);
	}
	return (int)calc();
}

int updateX(int pos, int val) {
	bit.add(pos,ppow(x[pos],MOD-2)*val%MOD);
	if(val==1){
		se.erase(pos);
	}
	else{
		se.insert(pos);
	}
	x[pos]=val;
	return (int)calc();
}

int updateY(int pos, int val) {
	y[pos]=val;
	seg.update(pos,val);
	return (int)calc();
}

Compilation message

horses.cpp: In member function 'void BIT::add(int, ll)':
horses.cpp:28:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(k<bit.size()){
         ~^~~~~~~~~~~
horses.cpp: In function 'll calc()':
horses.cpp:80:8: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
   if(M>1e9||s==se.begin())break;
        ^~~
horses.cpp:91:12: warning: conversion to 'll {aka long long int}' from '__int128' may alter its value [-Wconversion]
  return Max%MOD;
         ~~~^~~~
horses.cpp:75:5: warning: unused variable 'res' [-Wunused-variable]
  ll res=0;
     ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:100:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   seg.update(i,y[i]);
                ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 304 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 44560 KB Output is correct
2 Correct 373 ms 44664 KB Output is correct
3 Correct 342 ms 44536 KB Output is correct
4 Correct 436 ms 44632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 560 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 87 ms 24312 KB Output is correct
34 Correct 89 ms 24312 KB Output is correct
35 Correct 238 ms 54776 KB Output is correct
36 Correct 244 ms 54520 KB Output is correct
37 Correct 93 ms 22392 KB Output is correct
38 Correct 147 ms 35192 KB Output is correct
39 Correct 80 ms 22264 KB Output is correct
40 Correct 223 ms 49656 KB Output is correct
41 Correct 83 ms 22264 KB Output is correct
42 Correct 95 ms 22264 KB Output is correct
43 Correct 205 ms 50144 KB Output is correct
44 Correct 210 ms 50044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 296 ms 48608 KB Output is correct
34 Correct 395 ms 57208 KB Output is correct
35 Correct 353 ms 48376 KB Output is correct
36 Correct 428 ms 52192 KB Output is correct
37 Correct 92 ms 24312 KB Output is correct
38 Correct 92 ms 24312 KB Output is correct
39 Correct 250 ms 54520 KB Output is correct
40 Correct 288 ms 54648 KB Output is correct
41 Correct 90 ms 22392 KB Output is correct
42 Correct 148 ms 35192 KB Output is correct
43 Correct 80 ms 22136 KB Output is correct
44 Correct 253 ms 49784 KB Output is correct
45 Correct 84 ms 22264 KB Output is correct
46 Correct 90 ms 22264 KB Output is correct
47 Correct 245 ms 50012 KB Output is correct
48 Correct 232 ms 50100 KB Output is correct
49 Correct 167 ms 27388 KB Output is correct
50 Correct 158 ms 27256 KB Output is correct
51 Correct 379 ms 56648 KB Output is correct
52 Correct 350 ms 55928 KB Output is correct
53 Correct 247 ms 25644 KB Output is correct
54 Correct 253 ms 39208 KB Output is correct
55 Correct 135 ms 23288 KB Output is correct
56 Correct 349 ms 51496 KB Output is correct
57 Correct 151 ms 24056 KB Output is correct
58 Correct 194 ms 24568 KB Output is correct
59 Correct 265 ms 50040 KB Output is correct