Submission #483077

# Submission time Handle Problem Language Result Execution time Memory
483077 2021-10-27T16:11:39 Z Lam_lai_cuoc_doi popa (BOI18_popa) C++17
100 / 100
112 ms 304 KB
#include <bits/stdc++.h>
#include "popa.h"

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 1e3 + 5;
constexpr ll Inf = 1e17;
int *l, *r;

// Ảo thật đấy
// if b | a (a > 0) => b <= a
// => monotone stack

int solve(int n, int *Left, int *Right)
{
    l = Left;
    r = Right;

    for (int i = 0; i < n; ++i)
        l[i] = r[i] = -1;

    vector<int> s;

    for (int i = 0; i < n; ++i)
    {
        int maxn(-1);
        while (!s.empty() && !query(s.back(), i, s.back(), s.back()))
        {
            maxn = s.back();
            s.pop_back();
        }

        if (!s.empty())
            r[s.back()] = i;
        l[i] = maxn;

        s.emplace_back(i);
    }

    return s[0];
}
/*

void Read()
{
}

void Solve()
{
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("xor.INP", "r"))
    {
        freopen("xor.inp", "r", stdin);
        freopen("xor.out", "w", stdout);
    }
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        // cout << "Case #" << _ << ": ";
        Read();
        Solve();
    }
    // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

/**/

Compilation message

popa.cpp:89:1: warning: "/*" within comment [-Wcomment]
   89 | /**/
      |  
popa.cpp: In function 'void read(T&)':
popa.cpp:13:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 |     register int c;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 200 KB Output is correct
2 Correct 10 ms 200 KB Output is correct
3 Correct 4 ms 200 KB Output is correct
4 Correct 8 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 288 KB Output is correct
2 Correct 95 ms 280 KB Output is correct
3 Correct 72 ms 284 KB Output is correct
4 Correct 84 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 304 KB Output is correct
2 Correct 64 ms 284 KB Output is correct
3 Correct 112 ms 284 KB Output is correct
4 Correct 88 ms 280 KB Output is correct