QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691663#7660. Investigating Frog Behaviour on Lily Pad Patternsduong2803WA 1ms7776kbC++233.8kb2024-10-31 12:30:592024-10-31 12:30:59

Judging History

This is the latest submission verdict.

  • [2024-10-31 12:30:59]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7776kb
  • [2024-10-31 12:30:59]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s)
{
    return '"' + s + '"';
}

string to_string(const char* s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #define int long long

const int mxN = 2e6 + 5;
int fen[mxN];

void update(int i, int x)
{
    for (; i < mxN; i += i & -i)
        fen[i] += x;
}

int query(int l, int r)
{
    int res = 0;
    --l;

    for (; l > 0; l -= l & -l)
        res -= fen[l];
    for (; r > 0; r -= r & -r)
        res += fen[r];

    return res;
}

void solve()
{
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;

        update(x, 1);
    }

    int q;
    cin >> q;

    while (q--) {
        int j;
        cin >> j;

        int i;
        for (int l = 1, r = mxN - 1; l <= r;) {
            int m = l + r >> 1;
            int cnt = query(1, m);
            if (cnt == j){
                i = m;
                r = m - 1;
                continue; 
            }
            if(cnt > j){
                r = m - 1;
            }else
                l = m + 1;
        }

        int pos = i;
        for (int l = i, r = mxN - 1; l <= r;) {
            int m = l + r >> 1;
            int cnt = query(i, m);
            if (cnt == m - i + 1) {
                pos = m;
                l = m + 1;
            } else
                r = m - 1;
        }
        cout << pos + 1 << '\n';
        update(pos + 1, 1);
        update(i, -1);
    }
}

signed main()
{

#ifndef ONLINE_JUDGE
    freopen("out.txt", "w", stdout);
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7680kb

input:

5
1 2 3 5 7
3
1
2
4

output:

4
6
8

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 7676kb

input:

5
1 2 3 5 7
4
1
1
1
1

output:

4
6
8
9

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7776kb

input:

5
1 2 3 4 5
20
1
4
4
3
5
3
3
5
2
2
5
4
1
4
2
3
1
5
3
3

output:

6
7
8
5
9
6
8
10
4
5
11
9
3
10
6
8
4
12
9
11

result:

wrong answer 4th lines differ - expected: '4', found: '5'