답안 #621078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
621078 2022-08-03T11:50:49 Z amin 말 (IOI15_horses) C++14
100 / 100
484 ms 40204 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;

long long x[500001];
long long seg[2000002],segg[2000002],mu[2000002];
long long y[500001];
long long h=(1e9+1);
long long mod=1e9+7;
void build(long v,long tl,long tr)
{
    if(tl==tr)
    {
        seg[v]=x[tl];
        mu[v]=seg[v];
        return ;
    }
    long tm=(tl+tr)/2;
    build(v*2,tl,tm);
    build(v*2+1,tm+1,tr);
    seg[v]=seg[v*2]*seg[v*2+1];
    mu[v]=(mu[v*2]*mu[v*2+1])%mod;

    if(seg[v]>h)
    {
        seg[v]=h;
    }
}
void update(long v,long tl,long tr,long in)
{
    if(tl==tr&&tl==in)
    {
        seg[v]=x[in];
        mu[v]=seg[v];
        return ;
    }
    long tm=(tl+tr)/2;
    if(tm>=in)
    {
        update(v*2,tl,tm,in);
    }else
    {
        update(v*2+1,tm+1,tr,in);
    }
    seg[v]=seg[v*2]*seg[v*2+1];
    mu[v]=(mu[v*2]*mu[v*2+1])%mod;
    if(seg[v]>h)
    {
        seg[v]=h;
    }
}
long long get(long v,long tl,long tr,long l,long r)
{
    if(l==tl&&r==tr)
    {
        return seg[v];
    }
    long tm=(tl+tr)/2;
    if(r<=tm)
    {
        return get(v*2,tl,tm,l,r);
    }
    if(l>tm)
    {
        return get(v*2+1,tm+1,tr,l,r);
    }
    long long j=get(v*2,tl,tm,l,tm)*get(v*2+1,tm+1,tr,tm+1,r);
    if(j>h)
    {
        j=h;
    }
    return j;
}
long n;

void build2(long v,long tl,long tr)
{
    if(tl==tr)
    {
        segg[v]=tl;
        return ;
    }
    long tm=(tl+tr)/2;
    build2(v*2,tl,tm);
    build2(v*2+1,tm+1,tr);
    long long a=segg[v*2];
    long long b=segg[v*2+1];
   // cout<<a<<' '<<b<<' ';
   // cout<<y[a]<<' '<<y[b]*get(1,0,n-1,a+1,b)<<endl;
   if(b-a>200)
   {


    if(y[a]>(y[b]*get(1,0,n-1,a+1,b)))
    {
      segg[v]=a;

    }else
    {
        segg[v]=b;
    }
   }else
   {
       long long o=1;
       for(long i=a+1;i<=b;i++)
       {
           o*=x[i];
           if(o>h)
           {


            o=h;
            break;
           }
       }
       if(y[a]>(y[b]*o))
    {
      segg[v]=a;

    }else
    {
        segg[v]=b;
    }
   }
}
void update2(long v,long tl,long tr,long in)
{
    if(tl==tr)
    {
        segg[v]=tl;
        return ;
    }
    long tm=(tl+tr)/2;
    if(tm>=in)
    {
        update2(v*2,tl,tm,in);
    }else
    {
        update2(v*2+1,tm+1,tr,in);
    }
      long long a=segg[v*2];
    long long b=segg[v*2+1];
   // cout<<a<<' '<<b<<' ';
   // cout<<y[a]<<' '<<y[b]*get(1,0,n-1,a+1,b)<<endl;
    if(y[a]>(y[b]*get(1,0,n-1,a+1,b)))
    {
      segg[v]=a;

    }else
    {
        segg[v]=b;
    }

}
long long get2(long v,long tl,long tr,long l,long r)
{

    if(l==tl&&r==tr)
    {
        return mu[v];
    }
    long tm=(tl+tr)/2;
    if(r<=tm)
    {
        return get2(v*2,tl,tm,l,r);
    }
    if(l>tm)
    {
        return get2(v*2+1,tm+1,tr,l,r);
    }
    long long j=(get2(v*2,tl,tm,l,tm)*get2(v*2+1,tm+1,tr,tm+1,r))%mod;

    return j;
}
int init(int N, int X[], int Y[]) {
  //  cout<<mod<<endl;
    n=N;
    for(long i=0;i<n;i++)
    {
        x[i]=X[i];
        y[i]=Y[i];
    }
    build(1,0,n-1);
build2(1,0,n-1);

	long long ans=((get2(1,0,n-1,0,segg[1])*y[segg[1]])%mod);
	return ans;
}

int updateX(int pos, int val) {
   // pos--;
    x[pos]=val;
    update(1,0,n-1,pos);
	update2(1,0,n-1,pos);
	 // build(1,0,n-1);
//build2(1,0,n-1);
	long long ans=((get2(1,0,n-1,0,segg[1])*y[segg[1]])%mod);
	return ans;
}

int updateY(int pos, int val) {
   //  pos--;
    y[pos]=val;
    update(1,0,n-1,pos);
	update2(1,0,n-1,pos);
	//  build(1,0,n-1);
//build2(1,0,n-1);
long long ans=((get2(1,0,n-1,0,segg[1])*y[segg[1]])%mod);
	return ans;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:187:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  187 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:198:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  198 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:209:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  209 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 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 212 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 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 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 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 1 ms 340 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 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 408 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
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 37664 KB Output is correct
2 Correct 308 ms 37636 KB Output is correct
3 Correct 352 ms 37904 KB Output is correct
4 Correct 311 ms 38044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 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 1 ms 340 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 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 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 212 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 212 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 0 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 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 2 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 87 ms 36808 KB Output is correct
34 Correct 94 ms 39188 KB Output is correct
35 Correct 89 ms 38720 KB Output is correct
36 Correct 75 ms 38740 KB Output is correct
37 Correct 61 ms 38888 KB Output is correct
38 Correct 66 ms 39308 KB Output is correct
39 Correct 46 ms 38736 KB Output is correct
40 Correct 57 ms 39156 KB Output is correct
41 Correct 53 ms 38700 KB Output is correct
42 Correct 42 ms 38868 KB Output is correct
43 Correct 53 ms 39204 KB Output is correct
44 Correct 54 ms 39044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 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 229 ms 37556 KB Output is correct
34 Correct 266 ms 38560 KB Output is correct
35 Correct 365 ms 40092 KB Output is correct
36 Correct 343 ms 40032 KB Output is correct
37 Correct 93 ms 39200 KB Output is correct
38 Correct 86 ms 39104 KB Output is correct
39 Correct 104 ms 38836 KB Output is correct
40 Correct 81 ms 38804 KB Output is correct
41 Correct 65 ms 38904 KB Output is correct
42 Correct 55 ms 39124 KB Output is correct
43 Correct 50 ms 38656 KB Output is correct
44 Correct 59 ms 39116 KB Output is correct
45 Correct 49 ms 38792 KB Output is correct
46 Correct 43 ms 38780 KB Output is correct
47 Correct 52 ms 39084 KB Output is correct
48 Correct 53 ms 39024 KB Output is correct
49 Correct 484 ms 40132 KB Output is correct
50 Correct 468 ms 40108 KB Output is correct
51 Correct 251 ms 39736 KB Output is correct
52 Correct 157 ms 39660 KB Output is correct
53 Correct 380 ms 40028 KB Output is correct
54 Correct 225 ms 39984 KB Output is correct
55 Correct 118 ms 39336 KB Output is correct
56 Correct 142 ms 40204 KB Output is correct
57 Correct 243 ms 40032 KB Output is correct
58 Correct 158 ms 40112 KB Output is correct
59 Correct 52 ms 39124 KB Output is correct