답안 #781897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781897 2023-07-13T12:49:39 Z Lyrically 말 (IOI15_horses) C++17
100 / 100
159 ms 58364 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int read(){int x;scanf("%d",&x);return x;}
void print(int x){printf("%d\n",x);}
const int mod=1000000007;
long long n;
struct node
{
	long long ans,mul;
	double lgmul,lgans;
}seg[500005*4];
long long x[500005],y[500005];
void upd(int id)
{
	seg[id].mul=seg[id*2].mul*seg[id*2+1].mul%mod;
	seg[id].lgmul=seg[id*2].lgmul+seg[id*2+1].lgmul;
	double fi=seg[id*2].lgans;
	double se=seg[id*2].lgmul+seg[id*2+1].lgans;
	if(fi>se)
	{
		seg[id].ans=seg[id*2].ans;
		seg[id].lgans=seg[id*2].lgans;
	}
	else
	{
		seg[id].ans=seg[id*2].mul*seg[id*2+1].ans%mod;
		seg[id].lgans=seg[id*2].lgmul+seg[id*2+1].lgans;
	}
}
void build(int id,int l,int r)
{
	if(l==r)
	{
		seg[id].ans=x[l]*y[l]%mod;
		seg[id].mul=x[l];
		seg[id].lgmul=log(x[l]);
		seg[id].lgans=log(x[l])+log(y[l]);
		return;
	}
	int mid=(l+r)/2;
	build(id*2,l,mid);build(id*2+1,mid+1,r);
	upd(id);
}
void change(int id,int l,int r,int pos,long long val,int ty)
{
	if(l==r)
	{
		if(ty==0){x[l]=val;}
		else{y[l]=val;}
		seg[id].ans=x[l]*y[l]%mod;
		seg[id].mul=x[l];
		seg[id].lgmul=log(x[l]);
		seg[id].lgans=log(x[l])+log(y[l]);
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid){change(id*2,l,mid,pos,val,ty);}
	else{change(id*2+1,mid+1,r,pos,val,ty);}
	upd(id);
}
int init(int N,int X[],int Y[]){n=N;rep(i,n){x[i+1]=X[i];y[i+1]=Y[i];}build(1,1,n);return seg[1].ans;}
int updateX(int pos,int val){pos++;change(1,1,n,pos,val,0);return seg[1].ans;}
int updateY(int pos,int val){pos++;change(1,1,n,pos,val,1);return seg[1].ans;}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:65:81: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   65 | int init(int N,int X[],int Y[]){n=N;rep(i,n){x[i+1]=X[i];y[i+1]=Y[i];}build(1,1,n);return seg[1].ans;}
      |                                                                                 ^
horses.cpp:65:98: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   65 | int init(int N,int X[],int Y[]){n=N;rep(i,n){x[i+1]=X[i];y[i+1]=Y[i];}build(1,1,n);return seg[1].ans;}
      |                                                                                           ~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:66:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 | int updateX(int pos,int val){pos++;change(1,1,n,pos,val,0);return seg[1].ans;}
      |                                               ^
horses.cpp:66:74: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 | int updateX(int pos,int val){pos++;change(1,1,n,pos,val,0);return seg[1].ans;}
      |                                                                   ~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:67:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   67 | int updateY(int pos,int val){pos++;change(1,1,n,pos,val,1);return seg[1].ans;}
      |                                               ^
horses.cpp:67:74: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   67 | int updateY(int pos,int val){pos++;change(1,1,n,pos,val,1);return seg[1].ans;}
      |                                                                   ~~~~~~~^~~
horses.cpp: In function 'int read()':
horses.cpp:7:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | int read(){int x;scanf("%d",&x);return x;}
      |                  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 45968 KB Output is correct
2 Correct 159 ms 58364 KB Output is correct
3 Correct 106 ms 49552 KB Output is correct
4 Correct 117 ms 53504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 53 ms 48912 KB Output is correct
34 Correct 60 ms 48884 KB Output is correct
35 Correct 70 ms 55708 KB Output is correct
36 Correct 81 ms 55708 KB Output is correct
37 Correct 39 ms 46984 KB Output is correct
38 Correct 43 ms 47940 KB Output is correct
39 Correct 34 ms 46944 KB Output is correct
40 Correct 53 ms 50880 KB Output is correct
41 Correct 34 ms 46980 KB Output is correct
42 Correct 34 ms 46984 KB Output is correct
43 Correct 50 ms 51260 KB Output is correct
44 Correct 51 ms 51332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 436 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 65 ms 49612 KB Output is correct
34 Correct 138 ms 56828 KB Output is correct
35 Correct 117 ms 49592 KB Output is correct
36 Correct 135 ms 53380 KB Output is correct
37 Correct 52 ms 48864 KB Output is correct
38 Correct 52 ms 48836 KB Output is correct
39 Correct 79 ms 55732 KB Output is correct
40 Correct 75 ms 55752 KB Output is correct
41 Correct 38 ms 46980 KB Output is correct
42 Correct 43 ms 47948 KB Output is correct
43 Correct 34 ms 46848 KB Output is correct
44 Correct 58 ms 50860 KB Output is correct
45 Correct 35 ms 46948 KB Output is correct
46 Correct 34 ms 47044 KB Output is correct
47 Correct 50 ms 51144 KB Output is correct
48 Correct 50 ms 51256 KB Output is correct
49 Correct 118 ms 50884 KB Output is correct
50 Correct 117 ms 50900 KB Output is correct
51 Correct 104 ms 56784 KB Output is correct
52 Correct 98 ms 56804 KB Output is correct
53 Correct 106 ms 49304 KB Output is correct
54 Correct 77 ms 49776 KB Output is correct
55 Correct 59 ms 47928 KB Output is correct
56 Correct 84 ms 52640 KB Output is correct
57 Correct 65 ms 48536 KB Output is correct
58 Correct 62 ms 49088 KB Output is correct
59 Correct 58 ms 51260 KB Output is correct