답안 #53768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53768 2018-07-01T07:05:13 Z grumpy_gordon 유괴 2 (JOI17_abduction2) C++17
44 / 100
355 ms 43676 KB
/*
                     .:*+=%@@@@@@=-.
                 .:=@#@@@#@@#######%==*.
              .-=####@######%*-.....:%##%.
            .*@###########%+:--........-%@-
          .*@##############@+--.........-:%-
        .+##################@==%%%%=+*:----+.
      .-@####################%++%@@@@@=+**%@@*
      .%###################@%%@@@###@%+:--%@@%.
     -@###################@%%%%*::*%++:-----=@+.
    -#####################@%=++++++*:-------.-=:
   .+####################@%++*::-:::--::*:::***=:
   .@#####################%=++*::::-:::++*=##@@#@-
  ..#####################@%%=++**:::::**+%@#@%%##-..
   .%####################@@%=+++*+****::*=@######@.
  .=######################@%%==+==++**+=@%@##@###+:...
  -#######################@@@%%%===++=@@@%=++===*::--...
  -########################@@@@@@@%==%%=++==@@:::::*:--.
..:#########################@@@@@@%%======++++::-..:-.--...
%#############################@###@%%@@%==%=%*----.--.::---.
#############################################*-:*:-:---*---- .
#############################################*--*--:---*---:-.
#############################################+--::--::-*::-::.
###########################################+:*-.---.---.:---*-..
###########################################**:-----------------.
##########################################@::**:--::::::--:::::-
###########################################:--:*:::::::::**::*+*
###########################################=:::***::::::**:::*+*
############################@@@@@@#########@+****::::********+++
############################@%%%%%@@@@@@@###%+***::::::::***+==+
############################@%%%%%%%%%%%@####=+:::-::::-::*+=%%+
#############################@%%%%%%%%%%@#####=::--------:*=%@%+
%###########################@%%%%==%%%%%%@##@#=:------..-:+%@@%=
----------------------------------------------
--------------------------------------------
----------------------------------------------
--------------------------------------------
----------------------------------------------

         o###########oo
      o##"          ""##o
    o#"                "##
  o#"                    "#o
 #"  ##              ##   "##
#"                          ##
#  ###################       #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#o                           #
"#o                         ##
 "#o                       ##
  "#o                    o#"
   "#o                  ##
     "#o              o#"
       "#ooo      ooo#######oo
        ###############   "######o
     o###""        "###o      # ###
   o###o     oooo    ###    oo####"
 o###**#     #**#   ############"
 ""##""""""""""###########    #
    # oooooooo#"#**     ##    #
    # #       # # **    ##    #
    #o#       #o#  *****###ooo#
                        ##
                        ##   o###o
                        ## o##***##
               o########## #***#**##o
             o##"   ""###  #***##***#
 o#######o  ###   oo####   ##**####*#
o##"  ""#############""     ##****###
##"         ##              ##*##*###
##          ###              ##### ##
##           ###              # ##  #
##            ##                 #
##             ##
##             ###
##              ###oo
###              ""###
 ###
  ###
*/
#include <bits/stdc++.h>

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
//float __attribute__((aligned(32)))

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef unsigned int uint;

ll sqr(ll x){
    return x * x;
}

int mysqrt(ll x){
    int l = 0, r = 1e9 + 1;
    while (r - l > 1){
        int m = (l + r) / 2;
        if (m * (ll)m <= x)
            l = m;
        else
            r = m;
    }
    return l;
}

mt19937 rnd(1227);

mt19937_64 rndll(12365);

ll AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;

ll myrand(){
    ll ZR = (XR * AR + YR * BR + CR) % MODR;
    XR = YR;
    YR = ZR;
    return ZR;
}

const int Mod = 1e9 + 7;

int bpow(int x, int y){
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    int ret = bpow(x, y >> 1);
    ret = (ret * (ll)ret) % Mod;
    if (y & 1)
        ret = (ret * (ll)x) % Mod;
    return ret;
}

int bdiv(int x, int y){
    return (x * (ll)bpow(y, Mod - 2)) % Mod;
}

void setmin(int &x, int y){
    x = min(x, y);
}

void setmax(int &x, int y){
    x = max(x, y);
}

void setmin(ll &x, ll y){
    x = min(x, y);
}

void setmax(ll &x, ll y){
    x = max(x, y);
}

int gcd(int a, int b){
    return a ? gcd(b % a, a) : b;
}

const ll llinf = 2e18 + 100;

const double eps = 1e-9;

const int maxn = 5e4 + 10, maxw = 1e6 + 100, inf = 2e9 + 100, sq = 300, mod = 1e9 + 7, LG = 16;

int sp[2][LG][maxn];

int a[2][maxn];

int n[2];

int leg[maxn];

int get(int t, int l, int r){
    if (l > r)
        return -1;
    int lg = leg[r - l + 1];
    return max(sp[t][lg][l], sp[t][lg][r - (1 << lg) + 1]);
}

map<ll, int> ans;

int Get(int x, int y, int t){
    if (x < 0 || y < 0 || x >= n[0] || y >= n[1])
        return -1;
    ll w = (x * (ll)maxn + y) * 2 + t;
    if (ans.find(w) == ans.end()){
        int val = 0;
        int l, r;
        if (t == 0){
            l = -1, r = x;
            while (r - l > 1){
                int m = (l + r) / 2;
                if (get(0, m, x - 1) > a[1][y])
                    l = m;
                else
                    r = m;
            }
            val = x - l + Get(l, y, 1);
            l = x, r = n[0];
            while (r - l > 1){
                int m = (l + r) / 2;
                if (get(0, x + 1, m) > a[1][y])
                    r = m;
                else
                    l = m;
            }
            setmax(val, r - x + Get(r, y, 1));
        }else{
            l = -1, r = y;
            while (r - l > 1){
                int m = (l + r) / 2;
                if (get(1, m, y - 1) > a[0][x])
                    l = m;
                else
                    r = m;
            }
            val = y - l + Get(x, l, 0);
            l = y, r = n[1];
            while (r - l > 1){
                int m = (l + r) / 2;
                if (get(1, y + 1, m) > a[0][x])
                    r = m;
                else
                    l = m;
            }
            setmax(val, r - y + Get(x, r, 0));
        }
        ans[w] = val;
    }
    return ans[w];
}

void prec(){
    for (int i = 2; i < maxn; i++)
        leg[i] = leg[i >> 1] + 1;
    for (int t = 0; t < 2; t++)
        for (int j = 1; j < LG; j++)
            for (int i = 0; i + (1 << j) <= n[t]; i++)
                sp[t][j][i] = max(sp[t][j - 1][i], sp[t][j - 1][i + (1 << (j - 1))]);
}

int main()
{
    #ifdef ONPC
    //ifstream cin("a.in");
    //ofstream cout("a.out");
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    #else
    //ifstream cin("gymnasts.in");
    //ofstream cout("gymnasts.out");
    //freopen("sort.in", "r", stdin);
    //freopen("sort.out", "w", stdout);
    #endif // ONPC
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n[0] >> n[1];
    int zap;
    cin >> zap;
    for (int t = 0; t < 2; t++){
        for (int i = 0; i < n[t]; i++)
            cin >> a[t][i], sp[t][0][i] = a[t][i];
    }
    prec();
    while (zap--){
        int x, y;
        cin >> x >> y;
        cout << max(Get(x - 1, y - 1, 0), Get(x - 1, y - 1, 1)) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 948 KB Output is correct
7 Correct 2 ms 952 KB Output is correct
8 Correct 2 ms 956 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 2 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 948 KB Output is correct
7 Correct 2 ms 952 KB Output is correct
8 Correct 2 ms 956 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 2 ms 1088 KB Output is correct
12 Correct 3 ms 1292 KB Output is correct
13 Correct 4 ms 1432 KB Output is correct
14 Correct 5 ms 1432 KB Output is correct
15 Correct 3 ms 1432 KB Output is correct
16 Correct 3 ms 1484 KB Output is correct
17 Correct 3 ms 1540 KB Output is correct
18 Correct 3 ms 1596 KB Output is correct
19 Correct 5 ms 1764 KB Output is correct
20 Correct 6 ms 1932 KB Output is correct
21 Correct 6 ms 1972 KB Output is correct
22 Correct 8 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 948 KB Output is correct
7 Correct 2 ms 952 KB Output is correct
8 Correct 2 ms 956 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 2 ms 1088 KB Output is correct
12 Correct 3 ms 1292 KB Output is correct
13 Correct 4 ms 1432 KB Output is correct
14 Correct 5 ms 1432 KB Output is correct
15 Correct 3 ms 1432 KB Output is correct
16 Correct 3 ms 1484 KB Output is correct
17 Correct 3 ms 1540 KB Output is correct
18 Correct 3 ms 1596 KB Output is correct
19 Correct 5 ms 1764 KB Output is correct
20 Correct 6 ms 1932 KB Output is correct
21 Correct 6 ms 1972 KB Output is correct
22 Correct 8 ms 2140 KB Output is correct
23 Correct 21 ms 8576 KB Output is correct
24 Correct 27 ms 9544 KB Output is correct
25 Correct 29 ms 10512 KB Output is correct
26 Correct 24 ms 11476 KB Output is correct
27 Correct 22 ms 12440 KB Output is correct
28 Correct 56 ms 18016 KB Output is correct
29 Correct 123 ms 18016 KB Output is correct
30 Correct 126 ms 21420 KB Output is correct
31 Correct 145 ms 24220 KB Output is correct
32 Correct 30 ms 24220 KB Output is correct
33 Correct 58 ms 24220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 24220 KB Output is correct
2 Correct 5 ms 24220 KB Output is correct
3 Correct 5 ms 24220 KB Output is correct
4 Correct 6 ms 24220 KB Output is correct
5 Correct 6 ms 24220 KB Output is correct
6 Correct 5 ms 24220 KB Output is correct
7 Correct 5 ms 24220 KB Output is correct
8 Correct 8 ms 24220 KB Output is correct
9 Correct 9 ms 24220 KB Output is correct
10 Correct 8 ms 24220 KB Output is correct
11 Correct 9 ms 24220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 948 KB Output is correct
7 Correct 2 ms 952 KB Output is correct
8 Correct 2 ms 956 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 2 ms 1088 KB Output is correct
12 Correct 3 ms 1292 KB Output is correct
13 Correct 4 ms 1432 KB Output is correct
14 Correct 5 ms 1432 KB Output is correct
15 Correct 3 ms 1432 KB Output is correct
16 Correct 3 ms 1484 KB Output is correct
17 Correct 3 ms 1540 KB Output is correct
18 Correct 3 ms 1596 KB Output is correct
19 Correct 5 ms 1764 KB Output is correct
20 Correct 6 ms 1932 KB Output is correct
21 Correct 6 ms 1972 KB Output is correct
22 Correct 8 ms 2140 KB Output is correct
23 Correct 21 ms 8576 KB Output is correct
24 Correct 27 ms 9544 KB Output is correct
25 Correct 29 ms 10512 KB Output is correct
26 Correct 24 ms 11476 KB Output is correct
27 Correct 22 ms 12440 KB Output is correct
28 Correct 56 ms 18016 KB Output is correct
29 Correct 123 ms 18016 KB Output is correct
30 Correct 126 ms 21420 KB Output is correct
31 Correct 145 ms 24220 KB Output is correct
32 Correct 30 ms 24220 KB Output is correct
33 Correct 58 ms 24220 KB Output is correct
34 Correct 6 ms 24220 KB Output is correct
35 Correct 5 ms 24220 KB Output is correct
36 Correct 5 ms 24220 KB Output is correct
37 Correct 6 ms 24220 KB Output is correct
38 Correct 6 ms 24220 KB Output is correct
39 Correct 5 ms 24220 KB Output is correct
40 Correct 5 ms 24220 KB Output is correct
41 Correct 8 ms 24220 KB Output is correct
42 Correct 9 ms 24220 KB Output is correct
43 Correct 8 ms 24220 KB Output is correct
44 Correct 9 ms 24220 KB Output is correct
45 Correct 28 ms 24220 KB Output is correct
46 Correct 36 ms 24220 KB Output is correct
47 Correct 31 ms 24220 KB Output is correct
48 Correct 38 ms 24220 KB Output is correct
49 Correct 27 ms 24220 KB Output is correct
50 Correct 76 ms 28892 KB Output is correct
51 Correct 91 ms 30220 KB Output is correct
52 Correct 200 ms 36656 KB Output is correct
53 Correct 197 ms 37004 KB Output is correct
54 Correct 210 ms 37676 KB Output is correct
55 Incorrect 355 ms 43676 KB Output isn't correct
56 Halted 0 ms 0 KB -