답안 #731338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731338 2023-04-27T10:31:15 Z lucri 말 (IOI15_horses) C++17
77 / 100
1500 ms 50236 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;

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]);
}
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]);
}

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]);
}
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]);
}

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;
}
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;
}

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);
}
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));
}
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;
}


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();
      |         ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 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 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 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 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 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 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 3 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 12 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 316 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 9 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1159 ms 37720 KB Output is correct
2 Correct 233 ms 50236 KB Output is correct
3 Correct 314 ms 41456 KB Output is correct
4 Correct 228 ms 45236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 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 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 2 ms 308 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 9 ms 428 KB Output is correct
28 Correct 3 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 6 ms 340 KB Output is correct
32 Correct 12 ms 424 KB Output is correct
33 Correct 68 ms 40620 KB Output is correct
34 Correct 56 ms 40636 KB Output is correct
35 Correct 108 ms 47552 KB Output is correct
36 Correct 90 ms 47516 KB Output is correct
37 Correct 247 ms 38992 KB Output is correct
38 Correct 88 ms 39796 KB Output is correct
39 Correct 62 ms 38768 KB Output is correct
40 Correct 80 ms 42740 KB Output is correct
41 Correct 147 ms 38792 KB Output is correct
42 Correct 167 ms 38816 KB Output is correct
43 Correct 53 ms 43048 KB Output is correct
44 Correct 55 ms 42980 KB Output is correct
# 결과 실행 시간 메모리 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 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 2 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 8 ms 324 KB Output is correct
28 Correct 4 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 8 ms 432 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 1226 ms 41616 KB Output is correct
34 Correct 205 ms 50124 KB Output is correct
35 Correct 282 ms 41424 KB Output is correct
36 Correct 224 ms 45412 KB Output is correct
37 Correct 62 ms 40616 KB Output is correct
38 Correct 53 ms 40684 KB Output is correct
39 Correct 110 ms 47584 KB Output is correct
40 Correct 76 ms 47568 KB Output is correct
41 Correct 232 ms 38864 KB Output is correct
42 Correct 94 ms 39672 KB Output is correct
43 Correct 69 ms 38708 KB Output is correct
44 Correct 66 ms 42728 KB Output is correct
45 Correct 113 ms 38840 KB Output is correct
46 Correct 170 ms 38860 KB Output is correct
47 Correct 54 ms 42956 KB Output is correct
48 Correct 62 ms 43056 KB Output is correct
49 Correct 246 ms 42836 KB Output is correct
50 Correct 160 ms 42684 KB Output is correct
51 Correct 402 ms 49484 KB Output is correct
52 Correct 146 ms 48936 KB Output is correct
53 Execution timed out 1546 ms 40784 KB Time limit exceeded
54 Halted 0 ms 0 KB -