답안 #1050656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050656 2024-08-09T12:11:57 Z ArthuroWich 말 (IOI15_horses) C++17
37 / 100
360 ms 64608 KB
#include "horses.h"
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
void buildp(int n, int l, int r) {
    if (l == r) {
        segp[n] = x[l];
    } else {
        int m = (l+r)/2;
        buildp(2*n, l, m);
        buildp(2*n+1, m+1, r);
        segp[n] = segp[2*n] * segp[2*n+1];
        segp[n] %= mod;
    }
}
void buildm(int n, int l, int r) {
    if (l == r) {
        segm[n] = y[l];
    } else {
        int m = (l+r)/2;
        buildm(2*n, l, m);
        buildm(2*n+1, m+1, r);
        segm[n] = max(segm[2*n], segm[2*n+1]);
    }
}
void updatep(int n, int l, int r, int i, int v) {
    if (l == r) {
        segp[n] = v;
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            updatep(2*n, l, m, i, v);
        } else {
            updatep(2*n+1, m+1, r, i, v);
        }
        segp[n] = segp[2*n] * segp[2*n+1];
        segp[n] %= mod;
    }
}
void updatem(int n, int l, int r, int i, int v) {
    if (l == r) {
        segm[n] = v;
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            updatem(2*n, l, m, i, v);
        } else {
            updatem(2*n+1, m+1, r, i, v);
        }
        segm[n] = max(segm[2*n], segm[2*n+1]);
    }
}
int queryp(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 1;
    } else if (a <= l && r <= b) {
        return segp[n];
    } else {
        int m = (l+r)/2;
        return (queryp(2*n, l, m, a, b)*queryp(2*n+1, m+1, r, a, b))%mod;
    }
}
int querym(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 0;
    } else if (a <= l && r <= b) {
        return segm[n];
    } else {
        int m = (l+r)/2;
        return max(querym(2*n, l, m, a, b), querym(2*n+1, m+1, r, a, b));
    }
}
set<pair<int, int>> segs;
int32_t calc() {
    int ind = 0, co = 0;
    auto j = segs.end();
    while(j != segs.begin()) {
        if (co > 63) {
            break;
        }
        co++;
        j--;
    }
    long double v = 0, a = 0, b = 0;
    for (; j != segs.end(); j++) {
        auto [l, r] = *j;
        if (l == r) {
            a += log2(x[l]);
            if (a+log2(y[l]) > v) {
                v = a+log2(y[l]);
                ind = l;
            }
        } else {
            int mx = querym(1, 0, n-1, l, r);
            if (a+log2(mx) > v) {
                v = a+log2(mx);
                ind = l;
            }
        }
    
    }
    return (queryp(1, 0, n-1, 0, ind)*y[ind]) % mod;
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
    n = N;
    int l = -1, r = 0;
    for (int i = 0; i < n; i++) {
        if (x[i] == 1) {
            if (l != -1) {
                l = i;
            } 
            r = i;
        } else {
            if (l != -1) {
                segs.insert({l, r});
            }
            l = -1;
            segs.insert({i, i});
        }
        x[i] = X[i];
        y[i] = Y[i];
    }
    if (l != -1) {
        segs.insert({l, r});
    }
    buildp(1, 0, n-1);
    buildm(1, 0, n-1);
    return calc();
}
int32_t updateX(int32_t pos, int32_t val) {	
    if (x[pos] == 1 && val != 1) {
        auto i = segs.lower_bound({pos, pos});
        auto [l, r] = *i;
        segs.erase(i);
        if (l != pos) {
            segs.insert({l, pos-1});
        }
        segs.insert({pos, pos});
        if (r != pos) {
            segs.insert({pos+1, r});
        }
    } else if (x[pos] != 1 && val == 1) {
        auto i = segs.lower_bound({pos, pos});
        set<pair<int, int>> todel;
        todel.insert({pos, pos});
        int ll = pos, rr = pos;
        if (pos != 0 && x[pos-1] == 1) {
            i--;
            auto [l, r] = *i;
            ll = l;
            todel.insert({l, r});
            i++;
        }
        if (pos != n-1 && x[pos+1] == 1) {
            i++;
            auto [l, r] = *i;
            rr = r;
            todel.insert({l, r});
        }
        for (auto c : todel) {
            segs.erase(c);
        }
        segs.insert({ll, rr});
    }
    x[pos] = val;
    updatep(1, 0, n-1, pos, val);
    return calc();
}
int32_t updateY(int32_t pos, int32_t val) {
    y[pos] = val;
    updatem(1, 0, n-1, pos, val);
    return calc();
}

Compilation message

horses.cpp: In function 'void buildp(long long int, long long int, long long int)':
horses.cpp:6:17: warning: declaration of 'n' shadows a global declaration [-Wshadow]
    6 | void buildp(int n, int l, int r) {
      |                 ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'void buildm(long long int, long long int, long long int)':
horses.cpp:17:17: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   17 | void buildm(int n, int l, int r) {
      |                 ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'void updatep(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:27:18: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   27 | void updatep(int n, int l, int r, int i, int v) {
      |                  ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'void updatem(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:41:18: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   41 | void updatem(int n, int l, int r, int i, int v) {
      |                  ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'long long int queryp(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:54:16: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   54 | int queryp(int n, int l, int r, int a, int b) {
      |                ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'long long int querym(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:64:16: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   64 | int querym(int n, int l, int r, int a, int b) {
      |                ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'int32_t calc()':
horses.cpp:103:47: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  103 |     return (queryp(1, 0, n-1, 0, ind)*y[ind]) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:85:31: warning: unused variable 'b' [-Wunused-variable]
   85 |     long double v = 0, a = 0, b = 0;
      |                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6528 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6568 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6544 KB Output is correct
17 Correct 1 ms 6568 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 0 ms 4480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 0 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Runtime error 2 ms 4700 KB Execution killed with signal 6
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 62548 KB Output is correct
2 Correct 360 ms 64608 KB Output is correct
3 Correct 285 ms 62292 KB Output is correct
4 Correct 343 ms 63524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 6492 KB Output is correct
9 Correct 1 ms 6568 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6568 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Runtime error 3 ms 8796 KB Execution killed with signal 6
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 6492 KB Output is correct
9 Correct 0 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 0 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 0 ms 6492 KB Output is correct
16 Correct 1 ms 6568 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6580 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Runtime error 5 ms 12892 KB Execution killed with signal 6
23 Halted 0 ms 0 KB -