Submission #731343

# Submission time Handle Problem Language Result Execution time Memory
731343 2023-04-27T10:37:10 Z lucri Horses (IOI15_horses) C++17
100 / 100
1168 ms 44488 KB
//#include "horses.h"
#include <bits/stdc++.h>
#define MOD 1000000007
long long aintx[2000010],x[500010];
long long ainty[2000010],y[500010];
long long aintprod[2000010],n;

inline void initializeaintx(int poz,int b,int e)
{
    if(b==e)
    {
        aintx[poz]=(x[b]!=1);
        return;
    }
    initializeaintx(poz*2,b,(b+e)/2);
    initializeaintx(poz*2+1,(b+e)/2+1,e);
    aintx[poz]=(aintx[poz*2]|aintx[poz*2+1]);
}
inline void updateaintx(int poz,int b,int e,int pozm,int val)
{
    if(e<pozm||b>pozm)
        return;
    if(b==e)
    {
        aintx[poz]=(x[b]!=1);
        return;
    }
    updateaintx(poz*2,b,(b+e)/2,pozm,val);
    updateaintx(poz*2+1,(b+e)/2+1,e,pozm,val);
    aintx[poz]=(aintx[poz*2]|aintx[poz*2+1]);
}

inline void initializeainty(int poz,int b,int e)
{
    if(b==e)
    {
        ainty[poz]=y[b];
        return;
    }
    initializeainty(poz*2,b,(b+e)/2);
    initializeainty(poz*2+1,(b+e)/2+1,e);
    ainty[poz]=std::max(ainty[poz*2],ainty[poz*2+1]);
}
inline void updateainty(int poz,int b,int e,int pozm,int val)
{
    if(e<pozm||b>pozm)
        return;
    if(b==e)
    {
        ainty[poz]=y[b];
        return;
    }
    updateainty(poz*2,b,(b+e)/2,pozm,val);
    updateainty(poz*2+1,(b+e)/2+1,e,pozm,val);
    ainty[poz]=std::max(ainty[poz*2],ainty[poz*2+1]);
}

inline void initializeaintprod(int poz,int b,int e)
{
    if(b==e)
    {
        aintprod[poz]=x[b];
        return;
    }
    initializeaintprod(poz*2,b,(b+e)/2);
    initializeaintprod(poz*2+1,(b+e)/2+1,e);
    aintprod[poz]=aintprod[poz*2]*aintprod[poz*2+1]%MOD;
}
inline void updateaintprod(int poz,int b,int e,int pozm,int val)
{
    if(e<pozm||b>pozm)
        return;
    if(b==e)
    {
        aintprod[poz]=x[b];
        return;
    }
    updateaintprod(poz*2,b,(b+e)/2,pozm,val);
    updateaintprod(poz*2+1,(b+e)/2+1,e,pozm,val);
    aintprod[poz]=aintprod[poz*2]*aintprod[poz*2+1]%MOD;
}

inline long long difde0(int poz,int b,int e,int ei)
{
    if(b>=ei)
        return 0;
    if(aintx[poz]==0)
        return 0;
    if(b==e)
        return b;
    int poza=difde0(poz*2+1,(b+e)/2+1,e,ei);
    if(poza)
        return poza;
    return difde0(poz*2,b,(b+e)/2,ei);
}
inline long long maxim(int poz,int b,int e,int bi,int ei)
{
    if(b>ei||e<bi)
        return 0;
    if(bi<=b&&e<=ei)
        return ainty[poz];
    return std::max(maxim(poz*2,b,(b+e)/2,bi,ei),maxim(poz*2+1,(b+e)/2+1,e,bi,ei));
}
inline long long produs(int poz,int b,int e,int bi,int ei)
{
    if(b>ei||e<bi)
        return 1;
    if(bi<=b&&e<=ei)
        return aintprod[poz];
    return produs(poz*2,b,(b+e)/2,bi,ei)*produs(poz*2+1,(b+e)/2+1,e,bi,ei)%MOD;
}


inline long long calculeaza()
{
    long long prod=x[n]*y[n],pozant=n;
    while(prod<1000000000&&pozant)
    {
        int pozac=pozant;
        pozant=difde0(1,1,n,pozant);
        long long vmax=maxim(1,1,n,pozant,pozac-1);
        if(vmax>prod)
            prod=vmax;
        if(pozant!=0)
            prod*=x[pozant];
    }
    prod%=MOD;
    long long ans=prod*produs(1,1,n,1,pozant-1)%MOD;
    return ans;
}

int init(int N, int X[], int Y[])
{
    n=N;
    for(int i=1;i<=N;++i)
    {
        x[i]=X[i-1];
        y[i]=Y[i-1];
    }
    initializeaintx(1,1,N);
    initializeainty(1,1,N);
    initializeaintprod(1,1,N);
    return calculeaza();
}

int updateX(int pos, int val)
{
    ++pos;
    x[pos]=val;
    updateaintx(1,1,n,pos,val);
    updateaintprod(1,1,n,pos,val);
    calculeaza();
	return calculeaza();
}

int updateY(int pos, int val)
{
    ++pos;
    y[pos]=val;
    updateainty(1,1,n,pos,val);
    calculeaza();
	return calculeaza();
}

Compilation message

horses.cpp: In function 'long long int difde0(int, int, int, int)':
horses.cpp:91:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |     int poza=difde0(poz*2+1,(b+e)/2+1,e,ei);
      |              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'long long int calculeaza()':
horses.cpp:119:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |         int pozac=pozant;
      |                   ^~~~~~
horses.cpp:120:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  120 |         pozant=difde0(1,1,n,pozant);
      |                           ^
horses.cpp:120:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  120 |         pozant=difde0(1,1,n,pozant);
      |                             ^~~~~~
horses.cpp:121:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |         long long vmax=maxim(1,1,n,pozant,pozac-1);
      |                                  ^
horses.cpp:121:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |         long long vmax=maxim(1,1,n,pozant,pozac-1);
      |                                    ^~~~~~
horses.cpp:128:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  128 |     long long ans=prod*produs(1,1,n,1,pozant-1)%MOD;
      |                                   ^
horses.cpp:128:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  128 |     long long ans=prod*produs(1,1,n,1,pozant-1)%MOD;
      |                                       ~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:143:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  143 |     return calculeaza();
      |            ~~~~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:150:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  150 |     updateaintx(1,1,n,pos,val);
      |                     ^
horses.cpp:151:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  151 |     updateaintprod(1,1,n,pos,val);
      |                        ^
horses.cpp:153:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  153 |  return calculeaza();
      |         ~~~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:160:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  160 |     updateainty(1,1,n,pos,val);
      |                     ^
horses.cpp:162:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  162 |  return calculeaza();
      |         ~~~~~~~~~~^~
# 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 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 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 340 KB Output is correct
13 Correct 1 ms 212 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 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 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 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 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 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 1 ms 212 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 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 5 ms 424 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 860 ms 37768 KB Output is correct
2 Correct 162 ms 37672 KB Output is correct
3 Correct 250 ms 37588 KB Output is correct
4 Correct 159 ms 37580 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 212 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 1 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 1 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 212 KB Output is correct
19 Correct 0 ms 212 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 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 2 ms 348 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 5 ms 352 KB Output is correct
32 Correct 6 ms 340 KB Output is correct
33 Correct 50 ms 36692 KB Output is correct
34 Correct 46 ms 36732 KB Output is correct
35 Correct 84 ms 36776 KB Output is correct
36 Correct 63 ms 36740 KB Output is correct
37 Correct 155 ms 36784 KB Output is correct
38 Correct 55 ms 36724 KB Output is correct
39 Correct 48 ms 36636 KB Output is correct
40 Correct 55 ms 36744 KB Output is correct
41 Correct 102 ms 36812 KB Output is correct
42 Correct 122 ms 36768 KB Output is correct
43 Correct 44 ms 36592 KB Output is correct
44 Correct 43 ms 36624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 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 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 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 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 212 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 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 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 852 ms 37680 KB Output is correct
34 Correct 176 ms 37628 KB Output is correct
35 Correct 231 ms 37560 KB Output is correct
36 Correct 163 ms 37612 KB Output is correct
37 Correct 53 ms 36768 KB Output is correct
38 Correct 55 ms 36752 KB Output is correct
39 Correct 93 ms 36700 KB Output is correct
40 Correct 70 ms 36764 KB Output is correct
41 Correct 173 ms 36832 KB Output is correct
42 Correct 73 ms 36708 KB Output is correct
43 Correct 63 ms 36700 KB Output is correct
44 Correct 62 ms 36692 KB Output is correct
45 Correct 91 ms 36788 KB Output is correct
46 Correct 127 ms 36716 KB Output is correct
47 Correct 47 ms 36764 KB Output is correct
48 Correct 49 ms 36940 KB Output is correct
49 Correct 228 ms 37948 KB Output is correct
50 Correct 145 ms 37932 KB Output is correct
51 Correct 306 ms 38016 KB Output is correct
52 Correct 134 ms 38016 KB Output is correct
53 Correct 1168 ms 38104 KB Output is correct
54 Correct 310 ms 41520 KB Output is correct
55 Correct 221 ms 39828 KB Output is correct
56 Correct 211 ms 44488 KB Output is correct
57 Correct 610 ms 40392 KB Output is correct
58 Correct 971 ms 40924 KB Output is correct
59 Correct 51 ms 42956 KB Output is correct