답안 #298834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298834 2020-09-14T06:49:20 Z davooddkareshki 말 (IOI15_horses) C++17
100 / 100
1439 ms 115960 KB
//#include "horses.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
//#define int long long
#define F first
#define S second
#define pii pair<int,int>
#define mpr make_pair

const int maxn = 5e5+2;
const int mod = 1e9+7;
const ll inf = 1e9+10;

int n;
/// baraye Y --> tagir yek adad va maximom yek baze

int x[maxn], y[maxn];
struct segment_Y
{
    int mx[maxn<<2];
    void build(int v = 1, int tl = 1, int tr = n)
    {
        if(tl == tr)
        {
            mx[v] = y[tl];
            return;
        }

        int tm = (tl + tr) >> 1;
        build(v<<1, tl, tm);
        build(v<<1|1, tm+1, tr);
        mx[v] = max(mx[v<<1], mx[v<<1|1]);
    }

    void change(int pos, int val, int v = 1, int tl = 1, int tr = n)
    {
        if(tl == tr)
        {
            mx[v] = val;
            return;
        }

        int tm = (tl + tr) >> 1;
        if(pos <= tm) change(pos, val, v<<1, tl, tm);
        else          change(pos, val, v<<1|1, tm+1, tr);
        mx[v] = max(mx[v<<1],mx[v<<1|1]);
    }

    int qu(int l, int r, int v = 1, int tl = 1, int tr = n)
    {
        if(l > r) return 1;
        if(tl == l && tr == r) return mx[v];

        int tm = (tl + tr) >> 1;
        return max(qu(l, min(tm,r), v<<1, tl, tm),
                    qu(max(tm+1,l), r, v<<1|1, tm+1, tr));
    }
} seg_Y;

struct segment_X
{
    int mul[maxn<<2];
    void build(int v = 1, int tl = 1, int tr = n)
    {
        if(tl == tr)
        {
            mul[v] = x[tl];
            return;
        }

        int tm = (tl + tr) >> 1;
        build(v<<1, tl, tm);
        build(v<<1|1, tm+1, tr);
        mul[v] = (mul[v<<1] * 1ll * mul[v<<1|1]) % mod;
    }

    void change(int pos, int val, int v = 1, int tl = 1, int tr = n)
    {
        if(tl == tr)
        {
            mul[v] = val;
            return;
        }

        int tm = (tl + tr) >> 1;
        if(pos <= tm) change(pos, val, v<<1, tl, tm);
        else          change(pos, val, v<<1|1, tm+1, tr);
        mul[v] = (mul[v<<1] * 1ll * mul[v<<1|1]) % mod;
    }

    int qu(int l, int r, int v = 1, int tl = 1, int tr = n)
    {
        if(l > r) return 1;
        if(tl == l && tr == r) return mul[v];

        int tm = (tl + tr) >> 1;
        return (qu(l, min(tm,r), v<<1, tl, tm) * 1ll *
                qu(max(tm+1,l), r, v<<1|1, tm+1, tr)) % mod;
    }
} seg_X;

vector<int> seg[maxn<<2];
void buildX(int v = 1, int tl = 1, int tr = n)
{
    if(tl == tr)
    {
        if(x[tl] >= 2) seg[v].push_back(tl);
        return;
    }

    int tm = (tl + tr) >> 1;
    buildX(v<<1, tl, tm);
    buildX(v<<1|1, tm+1, tr);

    /// seg[v] nozolie
    seg[v].clear();
    for(auto x : seg[v<<1|1]) seg[v].push_back(x);
    for(auto x : seg[v<<1])   seg[v].push_back(x);
    while((int)seg[v].size() > 32ll) seg[v].pop_back();
}
void updX(int pos, int val, int v = 1, int tl = 1, int tr = n)
{
    if(tl == tr)
    {
        seg[v].clear();
        if(val >= 2) seg[v].push_back(tl);
        return;
    }

    int tm = (tl + tr) >> 1;
    if(pos <= tm) updX(pos, val, v<<1, tl, tm);
    else          updX(pos, val, v<<1|1, tm+1, tr);

    /// seg[v] nozolie
    seg[v].clear();
    for(auto x : seg[v<<1|1])
    {
        if((int)seg[v].size() > 30) break;
        seg[v].push_back(x);
    }
    for(auto x : seg[v<<1])
    {
        if((int)seg[v].size() > 30) break;
        seg[v].push_back(x);
    }
}

int mul(int a, int b) {return min(a*1ll*b,inf);}
int mult[33][33];

vector<int> X,Y;
bool cmp(int i, int j)
{
    /// if(i < j) return 1
    bool sw = 0;
    if(i > j) {sw = 1; swap(i,j);}

    return (sw ^ (Y[i] < mul(mult[i+1][j],Y[j])));
}
int answer()
{
    vector<int> ve = seg[1];
    bool DO = 0;
    if(ve.empty()) DO = 1;
    else if(ve.back() > 1) DO = 1;
    if(DO) ve.push_back(1);

    reverse(ve.begin(), ve.end());
    X.clear(); Y.clear();

    for(int i = 0; i < (int)ve.size(); i++)
    {
        X.push_back(x[ve[i]]);
        Y.push_back(seg_Y.qu(ve[i],n));
    }

    //for(int i = 0; i < 30; i++) for(int j = 0; j < 30; j++) mult[i][j] = 1;
    for(int l = 0; l < (int)X.size(); l++)
    {
        mult[l][l] = X[l];
        for(int r = l+1; r < (int)X.size(); r++)
            mult[l][r] = mul(mult[l][r-1],X[r]);
    }

    int j = 0;
    for(int i = 1; i < (int)ve.size(); i++)
        if(cmp(j,i)) j = i;

    int id = ve[j];
    return (seg_X.qu(1,id) * 1ll * Y[j]) % mod;
}


int init(int N, int X[], int Y[])
{
    n = N;
    x[0] = 1; y[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        x[i] = X[i-1];
        y[i] = Y[i-1];
    }
    seg_X.build();
    seg_Y.build();
    buildX();
    return answer();
}

int updateX(int pos, int val)
{
    pos++;
    x[pos] = val;
    updX(pos,val);
    seg_X.change(pos,val);
    return answer();
}

int updateY(int pos, int val)
{
    pos++;
    y[pos] = val;
    seg_Y.change(pos,val);
    return answer();
}
/*
int arrX[3] = {2,1,3};
int arrY[3] = {3,4,1};
signed main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cout<< init(3, arrX, arrY) <<"\n";
    cout<< updateY(1,2) <<"\n";
}
*/

Compilation message

horses.cpp: In member function 'void segment_X::build(int, int, int)':
horses.cpp:77:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   77 |         mul[v] = (mul[v<<1] * 1ll * mul[v<<1|1]) % mod;
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'void segment_X::change(int, int, int, int, int)':
horses.cpp:91:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |         mul[v] = (mul[v<<1] * 1ll * mul[v<<1|1]) % mod;
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'int segment_X::qu(int, int, int, int, int)':
horses.cpp:101:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  100 |         return (qu(l, min(tm,r), v<<1, tl, tm) * 1ll *
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  101 |                 qu(max(tm+1,l), r, v<<1|1, tm+1, tr)) % mod;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void buildX(int, int, int)':
horses.cpp:120:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  120 |     for(auto x : seg[v<<1|1]) seg[v].push_back(x);
      |              ^
horses.cpp:20:5: note: shadowed declaration is here
   20 | int x[maxn], y[maxn];
      |     ^
horses.cpp:121:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  121 |     for(auto x : seg[v<<1])   seg[v].push_back(x);
      |              ^
horses.cpp:20:5: note: shadowed declaration is here
   20 | int x[maxn], y[maxn];
      |     ^
horses.cpp: In function 'void updX(int, int, int, int, int)':
horses.cpp:139:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  139 |     for(auto x : seg[v<<1|1])
      |              ^
horses.cpp:20:5: note: shadowed declaration is here
   20 | int x[maxn], y[maxn];
      |     ^
horses.cpp:144:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  144 |     for(auto x : seg[v<<1])
      |              ^
horses.cpp:20:5: note: shadowed declaration is here
   20 | int x[maxn], y[maxn];
      |     ^
horses.cpp: In function 'int mul(int, int)':
horses.cpp:151:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  151 | int mul(int a, int b) {return min(a*1ll*b,inf);}
      |                               ~~~^~~~~~~~~~~~~
horses.cpp: In function 'int answer()':
horses.cpp:193:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  193 |     return (seg_X.qu(1,id) * 1ll * Y[j]) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:197:33: warning: declaration of 'Y' shadows a global declaration [-Wshadow]
  197 | int init(int N, int X[], int Y[])
      |                                 ^
horses.cpp:154:15: note: shadowed declaration is here
  154 | vector<int> X,Y;
      |               ^
horses.cpp:197:33: warning: declaration of 'X' shadows a global declaration [-Wshadow]
  197 | int init(int N, int X[], int Y[])
      |                                 ^
horses.cpp:154:13: note: shadowed declaration is here
  154 | vector<int> X,Y;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
3 Correct 36 ms 47360 KB Output is correct
4 Correct 34 ms 47352 KB Output is correct
5 Correct 33 ms 47360 KB Output is correct
6 Correct 33 ms 47352 KB Output is correct
7 Correct 32 ms 47352 KB Output is correct
8 Correct 33 ms 47352 KB Output is correct
9 Correct 33 ms 47360 KB Output is correct
10 Correct 32 ms 47352 KB Output is correct
11 Correct 34 ms 47480 KB Output is correct
12 Correct 32 ms 47352 KB Output is correct
13 Correct 32 ms 47356 KB Output is correct
14 Correct 38 ms 47352 KB Output is correct
15 Correct 32 ms 47352 KB Output is correct
16 Correct 33 ms 47488 KB Output is correct
17 Correct 32 ms 47360 KB Output is correct
18 Correct 32 ms 47360 KB Output is correct
19 Correct 33 ms 47488 KB Output is correct
20 Correct 33 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 33 ms 47360 KB Output is correct
3 Correct 32 ms 47352 KB Output is correct
4 Correct 32 ms 47360 KB Output is correct
5 Correct 33 ms 47360 KB Output is correct
6 Correct 33 ms 47488 KB Output is correct
7 Correct 33 ms 47352 KB Output is correct
8 Correct 33 ms 47360 KB Output is correct
9 Correct 33 ms 47360 KB Output is correct
10 Correct 33 ms 47360 KB Output is correct
11 Correct 32 ms 47360 KB Output is correct
12 Correct 32 ms 47360 KB Output is correct
13 Correct 32 ms 47352 KB Output is correct
14 Correct 32 ms 47360 KB Output is correct
15 Correct 34 ms 47360 KB Output is correct
16 Correct 33 ms 47360 KB Output is correct
17 Correct 33 ms 47352 KB Output is correct
18 Correct 33 ms 47360 KB Output is correct
19 Correct 33 ms 47356 KB Output is correct
20 Correct 33 ms 47360 KB Output is correct
21 Correct 33 ms 47352 KB Output is correct
22 Correct 33 ms 47360 KB Output is correct
23 Correct 38 ms 47360 KB Output is correct
24 Correct 40 ms 47360 KB Output is correct
25 Correct 38 ms 47488 KB Output is correct
26 Correct 39 ms 47488 KB Output is correct
27 Correct 38 ms 47360 KB Output is correct
28 Correct 39 ms 47480 KB Output is correct
29 Correct 33 ms 47360 KB Output is correct
30 Correct 39 ms 47480 KB Output is correct
31 Correct 36 ms 47360 KB Output is correct
32 Correct 38 ms 47360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 985 ms 104952 KB Output is correct
2 Correct 1236 ms 105208 KB Output is correct
3 Correct 1201 ms 104752 KB Output is correct
4 Correct 1439 ms 104696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 33 ms 47360 KB Output is correct
3 Correct 33 ms 47360 KB Output is correct
4 Correct 32 ms 47352 KB Output is correct
5 Correct 32 ms 47356 KB Output is correct
6 Correct 32 ms 47360 KB Output is correct
7 Correct 33 ms 47352 KB Output is correct
8 Correct 33 ms 47360 KB Output is correct
9 Correct 33 ms 47360 KB Output is correct
10 Correct 34 ms 47352 KB Output is correct
11 Correct 33 ms 47360 KB Output is correct
12 Correct 33 ms 47352 KB Output is correct
13 Correct 32 ms 47360 KB Output is correct
14 Correct 33 ms 47360 KB Output is correct
15 Correct 32 ms 47352 KB Output is correct
16 Correct 32 ms 47360 KB Output is correct
17 Correct 32 ms 47360 KB Output is correct
18 Correct 33 ms 47420 KB Output is correct
19 Correct 33 ms 47360 KB Output is correct
20 Correct 32 ms 47360 KB Output is correct
21 Correct 33 ms 47360 KB Output is correct
22 Correct 33 ms 47360 KB Output is correct
23 Correct 38 ms 47360 KB Output is correct
24 Correct 40 ms 47352 KB Output is correct
25 Correct 38 ms 47484 KB Output is correct
26 Correct 40 ms 47488 KB Output is correct
27 Correct 39 ms 47360 KB Output is correct
28 Correct 40 ms 47480 KB Output is correct
29 Correct 33 ms 47360 KB Output is correct
30 Correct 39 ms 47616 KB Output is correct
31 Correct 37 ms 47360 KB Output is correct
32 Correct 37 ms 47360 KB Output is correct
33 Correct 173 ms 65144 KB Output is correct
34 Correct 165 ms 65272 KB Output is correct
35 Correct 339 ms 103928 KB Output is correct
36 Correct 338 ms 104056 KB Output is correct
37 Correct 161 ms 65172 KB Output is correct
38 Correct 272 ms 92408 KB Output is correct
39 Correct 79 ms 64376 KB Output is correct
40 Correct 345 ms 104056 KB Output is correct
41 Correct 109 ms 64504 KB Output is correct
42 Correct 148 ms 64424 KB Output is correct
43 Correct 246 ms 103928 KB Output is correct
44 Correct 245 ms 103928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47488 KB Output is correct
2 Correct 33 ms 47360 KB Output is correct
3 Correct 33 ms 47356 KB Output is correct
4 Correct 33 ms 47608 KB Output is correct
5 Correct 34 ms 47352 KB Output is correct
6 Correct 35 ms 47360 KB Output is correct
7 Correct 33 ms 47488 KB Output is correct
8 Correct 32 ms 47360 KB Output is correct
9 Correct 32 ms 47360 KB Output is correct
10 Correct 32 ms 47360 KB Output is correct
11 Correct 32 ms 47480 KB Output is correct
12 Correct 33 ms 47352 KB Output is correct
13 Correct 32 ms 47352 KB Output is correct
14 Correct 33 ms 47352 KB Output is correct
15 Correct 32 ms 47360 KB Output is correct
16 Correct 33 ms 47360 KB Output is correct
17 Correct 34 ms 47352 KB Output is correct
18 Correct 34 ms 47488 KB Output is correct
19 Correct 33 ms 47360 KB Output is correct
20 Correct 32 ms 47360 KB Output is correct
21 Correct 33 ms 47352 KB Output is correct
22 Correct 33 ms 47360 KB Output is correct
23 Correct 38 ms 47392 KB Output is correct
24 Correct 39 ms 47480 KB Output is correct
25 Correct 39 ms 47488 KB Output is correct
26 Correct 39 ms 47424 KB Output is correct
27 Correct 37 ms 47352 KB Output is correct
28 Correct 38 ms 47488 KB Output is correct
29 Correct 34 ms 47360 KB Output is correct
30 Correct 39 ms 47608 KB Output is correct
31 Correct 36 ms 47360 KB Output is correct
32 Correct 38 ms 47360 KB Output is correct
33 Correct 1010 ms 105356 KB Output is correct
34 Correct 1277 ms 104708 KB Output is correct
35 Correct 1205 ms 104696 KB Output is correct
36 Correct 1409 ms 104784 KB Output is correct
37 Correct 174 ms 68216 KB Output is correct
38 Correct 166 ms 68088 KB Output is correct
39 Correct 352 ms 113812 KB Output is correct
40 Correct 358 ms 113784 KB Output is correct
41 Correct 166 ms 66168 KB Output is correct
42 Correct 280 ms 94328 KB Output is correct
43 Correct 81 ms 65400 KB Output is correct
44 Correct 344 ms 108920 KB Output is correct
45 Correct 109 ms 65528 KB Output is correct
46 Correct 143 ms 65656 KB Output is correct
47 Correct 252 ms 109432 KB Output is correct
48 Correct 257 ms 109432 KB Output is correct
49 Correct 1067 ms 74428 KB Output is correct
50 Correct 990 ms 74360 KB Output is correct
51 Correct 1102 ms 115960 KB Output is correct
52 Correct 1078 ms 115448 KB Output is correct
53 Correct 1045 ms 71800 KB Output is correct
54 Correct 1168 ms 98296 KB Output is correct
55 Correct 212 ms 66552 KB Output is correct
56 Correct 1245 ms 110712 KB Output is correct
57 Correct 507 ms 67192 KB Output is correct
58 Correct 872 ms 67704 KB Output is correct
59 Correct 248 ms 109288 KB Output is correct