Submission #540265

# Submission time Handle Problem Language Result Execution time Memory
540265 2022-03-19T18:31:52 Z Evang Editor (BOI15_edi) C++17
15 / 100
82 ms 28108 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)

#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define die exit(0)

template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;

constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------


const int N = 3e5+5;
const int LG = 20;
int n, a[N], ind[N], up[N][LG];
bitset<N> op;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout << fixed; clog << fixed; clog << unitbuf;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        if(a[i]<0) {
            op[i] = 1;
            a[i] = abs(a[i]);
            int j = i-1;
            for(int k = 19; k >= 0; --k)
                if(op[up[j][k]]&&a[up[j][k]]>=a[i])
                    j = up[j][k];
            if(op[j])
                j = up[j][0];
            ind[i] = j-1;

            up[i][0] = ind[i];
            while(op[up[i][0]]&&a[up[i][0]]>=a[i])
                up[i][0] = up[up[i][0]][0];
        }else
            up[i][0] = ind[i] = i;

        for(int j = 1; j < LG; ++j)
            up[i][j] = up[up[i][j-1]][j-1];
    }

    for(int i = 0; i < 20; ++i)
        for(int j = n; j > 0; --j)
            ind[j] = ind[ind[j]];

    for(int i = 1; i <= n; ++i)
        cout << a[ind[i]] << el;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 28108 KB Output is correct
2 Correct 80 ms 28072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 14072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -