답안 #731341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731341 2023-04-27T10:34:11 Z lucri 말 (IOI15_horses) C++17
77 / 100
1500 ms 38548 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:24: 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:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |             int pozac=pozant;
      |                       ^~~~~~
horses.cpp:120:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  120 |             pozant=difde0(1,1,n,pozant);
      |                               ^
horses.cpp:120:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  120 |             pozant=difde0(1,1,n,pozant);
      |                                 ^~~~~~
horses.cpp:121:38: 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:40: 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:39: 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:49: 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:26: 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:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  150 |         updateaintx(1,1,n,pos,val);
      |                         ^
horses.cpp:151:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  151 |         updateaintprod(1,1,n,pos,val);
      |                            ^
horses.cpp:153:23: 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:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  160 |         updateainty(1,1,n,pos,val);
      |                         ^
horses.cpp:162:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  162 |      return calculeaza();
      |             ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 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 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 340 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 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 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 1 ms 312 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 448 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 9 ms 320 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 452 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 9 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1275 ms 38164 KB Output is correct
2 Correct 193 ms 38388 KB Output is correct
3 Correct 300 ms 38376 KB Output is correct
4 Correct 189 ms 38336 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 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 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 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 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 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 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 8 ms 428 KB Output is correct
33 Correct 58 ms 37472 KB Output is correct
34 Correct 53 ms 37492 KB Output is correct
35 Correct 109 ms 37460 KB Output is correct
36 Correct 77 ms 37540 KB Output is correct
37 Correct 230 ms 37548 KB Output is correct
38 Correct 70 ms 37460 KB Output is correct
39 Correct 60 ms 37456 KB Output is correct
40 Correct 76 ms 37536 KB Output is correct
41 Correct 144 ms 37448 KB Output is correct
42 Correct 169 ms 37620 KB Output is correct
43 Correct 47 ms 37456 KB Output is correct
44 Correct 47 ms 37452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 312 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 0 ms 340 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 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 1 ms 340 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 432 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 4 ms 444 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 12 ms 320 KB Output is correct
28 Correct 4 ms 436 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 320 KB Output is correct
32 Correct 8 ms 428 KB Output is correct
33 Correct 1236 ms 38376 KB Output is correct
34 Correct 182 ms 38516 KB Output is correct
35 Correct 357 ms 38368 KB Output is correct
36 Correct 185 ms 38344 KB Output is correct
37 Correct 58 ms 37516 KB Output is correct
38 Correct 49 ms 37452 KB Output is correct
39 Correct 97 ms 37528 KB Output is correct
40 Correct 69 ms 37524 KB Output is correct
41 Correct 260 ms 37608 KB Output is correct
42 Correct 79 ms 37432 KB Output is correct
43 Correct 61 ms 37416 KB Output is correct
44 Correct 64 ms 37504 KB Output is correct
45 Correct 117 ms 37528 KB Output is correct
46 Correct 178 ms 37524 KB Output is correct
47 Correct 48 ms 37512 KB Output is correct
48 Correct 47 ms 37464 KB Output is correct
49 Correct 283 ms 38344 KB Output is correct
50 Correct 160 ms 38368 KB Output is correct
51 Correct 391 ms 38548 KB Output is correct
52 Correct 146 ms 38452 KB Output is correct
53 Execution timed out 1566 ms 38348 KB Time limit exceeded
54 Halted 0 ms 0 KB -