답안 #1036542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036542 2024-07-27T13:45:05 Z vjudge1 말 (IOI15_horses) C++17
17 / 100
381 ms 37204 KB
#include "horses.h"

#include <bits/stdc++.h>
using namespace std;

using lint=long long;

const lint mod=1e9+7;
const int lim=5e5+100;
const int inf=1e9;

int mul(lint i,lint j){
	return i*j%mod;
}

int n,*x,*y;

struct{
	int tree[4*lim];
	int P,VAL;
	int update(int l,int r,int node){
		if(l==r){
			return tree[node]=VAL;
		}
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return tree[node]=mul(update(l,mid,child),tree[child|1]);
		return tree[node]=mul(tree[child],update(mid+1,r,child|1));
	}
	void update(int p,int val){
		P=p,VAL=val;
		update(0,n-1,1);
	}
	int query(int l,int r,int node){
		if(r<=P){
			return tree[node];
		}
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return query(l,mid,child);
		return mul(tree[child],query(mid+1,r,child|1));
	}
	int query(int p){
		P=p;
		return query(0,n-1,1);
	}
}stmul;

struct{
	int tree[4*lim];
	int P,VAL;
	int update(int l,int r,int node){
		if(l==r)return tree[node]=VAL;
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return tree[node]=max(update(l,mid,child),tree[child|1]);
		return tree[node]=max(tree[child],update(mid+1,r,child|1));
	}
	void update(int p,int val){
		P=p,VAL=val;
		update(0,n-1,1);
	}
	int L,R;
	int query(int l,int r,int node){
		if(L<=l&&r<=R)return tree[node];
		if(r<L||R<l)return 0;
		int mid=(l+r)>>1,child=node<<1;
		return max(query(l,mid,child),query(mid+1,r,child|1));
	}
	int query(int l,int r){
		L=l,R=r;
		return query(0,n-1,1);
	}
}stmax;

set<int,greater<int>>nonones;

int findmax(){
	if(*nonones.begin()==-1)return stmax.query(0,n-1);
	int past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
	lint curbest=mul(aa,bb),temp=aa*x[past];
	if(inf<temp)return curbest;
	for(auto p=next(nonones.begin());p!=nonones.end();p++){
		int pp=*p;
		if(pp==-1){
			if(past==0)break;
			pp=0;
		}
		aa=stmax.query(pp,past-1);
		if(temp<aa){
			bb=stmul.query(pp);
			curbest=mul(aa,bb);
			temp=aa;
		}
		temp*=x[pp];
		if(inf<temp)return curbest;
		past=pp;
	}
	return curbest;
}

int init(int N, int X[], int Y[]) {
	n=N,x=X,y=Y;
	nonones.insert(-1);
	for(int i=0;i<n;i++){
		stmul.update(i,x[i]);
		stmax.update(i,y[i]);
		if(X[i]!=1)nonones.insert(i);
	}
	return findmax();
}

int updateX(int pos, int val) {	
	if(x[pos]!=1)nonones.erase(pos);
	x[pos]=val;
	stmul.update(pos,val);
	if(x[pos]!=1)nonones.insert(pos);
	return findmax();
}

int updateY(int pos, int val) {
	stmax.update(pos,val);
	return findmax();
}

Compilation message

horses.cpp: In function 'int mul(lint, lint)':
horses.cpp:13:12: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
   13 |  return i*j%mod;
      |         ~~~^~~~
horses.cpp: In function 'int findmax()':
horses.cpp:79:21: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |  if(inf<temp)return curbest;
      |                     ^~~~~~~
horses.cpp:93:22: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
   93 |   if(inf<temp)return curbest;
      |                      ^~~~~~~
horses.cpp:96:9: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
   96 |  return curbest;
      |         ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 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 348 KB Output is correct
9 Correct 1 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 0 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 2396 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 344 KB Output is correct
18 Correct 1 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 1 ms 2392 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 600 KB Output is correct
8 Correct 0 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 348 KB Output is correct
12 Correct 0 ms 2444 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 2396 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 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 381 ms 37100 KB Output is correct
2 Incorrect 303 ms 37204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 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 1 ms 348 KB Output is correct
6 Correct 0 ms 344 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 0 ms 2396 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 2392 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 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 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 348 KB Output is correct
9 Correct 1 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 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 2396 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 344 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 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -