Submission #640019

# Submission time Handle Problem Language Result Execution time Memory
640019 2022-09-13T09:48:40 Z ggoh Horses (IOI15_horses) C++14
100 / 100
1237 ms 62760 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;
typedef pair<int,int> pii;

int Z=1e9+7;
int n;
int po(int p,int q)
{
	if(q==0)return 1;
	if(q==1)return p;
	int o=po(p,q/2);
	o=1ll*o*o%Z;
	if(q%2)o=1ll*o*p%Z;
	return o;
}
struct Tree{
	long double l;
	int v;
}seg[1<<20];
long double lazyL[1<<20];
int lazyV[1<<20];
int XX[500005],YY[500005];

void push(int num,int s,int e)
{
	seg[num].l+=lazyL[num];
	if(s!=e)
	{
		lazyL[2*num]+=lazyL[num];
		lazyL[2*num+1]+=lazyL[num];
	}
	lazyL[num]=0;
	seg[num].v=1ll*seg[num].v*lazyV[num]%Z;
	if(s!=e)
	{
		lazyV[2*num]=1ll*lazyV[2*num]*lazyV[num]%Z;
		lazyV[2*num+1]=1ll*lazyV[2*num+1]*lazyV[num]%Z;
	}
	lazyV[num]=1;
}
void update(int num,int s,int e,int l,int r,long double x,int z)
{
	push(num,s,e);
	if(s>r||l>e)return ;
	if(l<=s&&e<=r)
	{
		seg[num].l+=x;
		seg[num].v=1ll*seg[num].v*z%Z;
		if(s!=e)
		{
			lazyL[num*2]+=x;
			lazyL[num*2+1]+=x;
			lazyV[num*2]=1ll*lazyV[num*2]*z%Z;
			lazyV[num*2+1]=1ll*lazyV[num*2+1]*z%Z;
		}
		return ;
	}
	update(num*2,s,(s+e)/2,l,r,x,z);
	update(num*2+1,(s+e)/2+1,e,l,r,x,z);
	if(seg[num*2].l>seg[num*2+1].l)
	{
		seg[num].l=seg[num*2].l;
		seg[num].v=seg[num*2].v;
	}
	else
	{
		seg[num].l=seg[num*2+1].l;
		seg[num].v=seg[num*2+1].v;
	}
}

int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=1;i<min(4*n,(1<<20));i++)lazyV[i]=seg[i].v=1;
	for(int i=0;i<n;i++)
	{
		long double x=log(X[i]);
		long double y=log(Y[i]);
		XX[i]=X[i];
		YY[i]=Y[i];
		update(1,0,n-1,i,n-1,x,X[i]);
		update(1,0,n-1,i,i,y,Y[i]);
	}
	return seg[1].v;
}

int updateX(int pos, int val) {
	long double x0=log(XX[pos]);
	long double x1=log(val);
	int mul=1ll*po(XX[pos],Z-2)*val%Z;
	XX[pos]=val;
	update(1,0,n-1,pos,n-1,x1-x0,mul);
	return seg[1].v;
}

int updateY(int pos, int val) {
	long double y0=log(YY[pos]);
	long double y1=log(val);
	int mul=1ll*po(YY[pos],Z-2)*val%Z;
	YY[pos]=val;
	update(1,0,n-1,pos,pos,y1-y0,mul);
	return seg[1].v;
}

Compilation message

horses.cpp: In function 'int po(int, int)':
horses.cpp:15:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  o=1ll*o*o%Z;
      |    ~~~~~~~^~
horses.cpp:16:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |  if(q%2)o=1ll*o*p%Z;
      |           ~~~~~~~^~
horses.cpp: In function 'void push(int, int, int)':
horses.cpp:36:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   36 |  seg[num].v=1ll*seg[num].v*lazyV[num]%Z;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp:39:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   39 |   lazyV[2*num]=1ll*lazyV[2*num]*lazyV[num]%Z;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp:40:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |   lazyV[2*num+1]=1ll*lazyV[2*num+1]*lazyV[num]%Z;
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'void update(int, int, int, int, int, long double, int)':
horses.cpp:51:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |   seg[num].v=1ll*seg[num].v*z%Z;
      |              ~~~~~~~~~~~~~~~~^~
horses.cpp:56:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   56 |    lazyV[num*2]=1ll*lazyV[num*2]*z%Z;
      |                 ~~~~~~~~~~~~~~~~~~^~
horses.cpp:57:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   57 |    lazyV[num*2+1]=1ll*lazyV[num*2+1]*z%Z;
      |                   ~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:93:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |  int mul=1ll*po(XX[pos],Z-2)*val%Z;
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:102:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  102 |  int mul=1ll*po(YY[pos],Z-2)*val%Z;
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1086 ms 62548 KB Output is correct
2 Correct 1221 ms 62388 KB Output is correct
3 Correct 1161 ms 62480 KB Output is correct
4 Correct 1169 ms 62544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 977 ms 61552 KB Output is correct
34 Correct 958 ms 61528 KB Output is correct
35 Correct 1008 ms 61732 KB Output is correct
36 Correct 1016 ms 61644 KB Output is correct
37 Correct 926 ms 61564 KB Output is correct
38 Correct 937 ms 61500 KB Output is correct
39 Correct 940 ms 61616 KB Output is correct
40 Correct 998 ms 61724 KB Output is correct
41 Correct 936 ms 61704 KB Output is correct
42 Correct 924 ms 61460 KB Output is correct
43 Correct 1042 ms 61492 KB Output is correct
44 Correct 1016 ms 61444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1065 ms 62640 KB Output is correct
34 Correct 1237 ms 62500 KB Output is correct
35 Correct 1120 ms 62492 KB Output is correct
36 Correct 1165 ms 62640 KB Output is correct
37 Correct 986 ms 61640 KB Output is correct
38 Correct 966 ms 61520 KB Output is correct
39 Correct 1029 ms 61660 KB Output is correct
40 Correct 1045 ms 61476 KB Output is correct
41 Correct 944 ms 61516 KB Output is correct
42 Correct 971 ms 61500 KB Output is correct
43 Correct 915 ms 61500 KB Output is correct
44 Correct 981 ms 61536 KB Output is correct
45 Correct 915 ms 61500 KB Output is correct
46 Correct 933 ms 61552 KB Output is correct
47 Correct 981 ms 61452 KB Output is correct
48 Correct 1008 ms 61500 KB Output is correct
49 Correct 1189 ms 62360 KB Output is correct
50 Correct 1184 ms 62444 KB Output is correct
51 Correct 1130 ms 62428 KB Output is correct
52 Correct 1144 ms 62476 KB Output is correct
53 Correct 1131 ms 62360 KB Output is correct
54 Correct 1098 ms 62472 KB Output is correct
55 Correct 1063 ms 61776 KB Output is correct
56 Correct 1157 ms 62760 KB Output is correct
57 Correct 1050 ms 62484 KB Output is correct
58 Correct 1069 ms 62404 KB Output is correct
59 Correct 994 ms 61604 KB Output is correct