QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293496#7969. 套娃samneverWA 4ms28316kbC++175.2kb2023-12-29 11:31:062023-12-29 11:31:09

Judging History

你现在查看的是最新测评结果

  • [2023-12-29 11:31:09]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:28316kb
  • [2023-12-29 11:31:06]
  • 提交

answer

#include<cstdio>
#include<ctime>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>
#include<random>
#include<numeric>
#include<set>
#include<functional>
#define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)
#define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)
#define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])
// #define ls(x) ch[x][0]
// #define rs(x) ch[x][1]
#define mpi(x,y) make_pair(x,y)
#define pi pair<int,int>
#define fi first
#define se second
// #define int ll
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
template<typename T>
void read(T& x) {
    x = 0; char ch = getchar(); bool f = 0;
    while (ch < '0' || ch > '9') {
        if (ch == '-')f = 1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
    x = f ? -x : x;
}
template<typename T, typename...Args>
void read(T& x, Args &...args) {
    read(x); read(args...);
}

const int N = 1e6 + 7, inf = 1e9 + 7;
int n, m;
int a[N];
vector<int>wt[N];

#define ls(k) (k<<1)
#define rs(k) (k<<1|1)
struct SEG {
    int p[N], tag[N], mnd[N];
    void pup(int k) {
        p[k] = max(p[ls(k)], p[rs(k)]);
        mnd[k] = min(mnd[ls(k)], mnd[rs(k)]);
    }
    void build(int k, int l, int r) {
        if (l == r) {
            p[k] = l; mnd[k] = 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(ls(k), l, mid); build(rs(k), mid + 1, r);
        pup(k);
    }
    void pdw(int k, int l, int r, int mid) {
        if (!tag[k])return;
        tag[ls(k)] = tag[k];
        p[ls(k)] = tag[k];
        mnd[ls(k)] = tag[k] - mid + 1;
        tag[rs(k)] = tag[k];
        p[rs(k)] = tag[k];
        mnd[rs(k)] = tag[k] - r + 1;
        tag[k] = 0;
    }
    void mdy(int k, int l, int r, int x, int y, int v) {
        if (x <= l && r <= y) {
            p[k] = v; tag[k] = v; mnd[k] = v - r + 1;
            return;
        }
        int mid = (l + r) >> 1; pdw(k, l, r, mid);
        if (x <= mid)mdy(ls(k), l, mid, x, y, v);
        if (mid < y)mdy(rs(k), mid + 1, r, x, y, v);
        pup(k);
    }
    int qrymnd(int k, int l, int r, int x, int y) {
        if (x <= l && r <= y)return mnd[k];
        int mid = (l + r) >> 1; pdw(k, l, r, mid);
        int res = inf;
        if (x <= mid)res = min(res, qrymnd(ls(k), l, mid, x, y));
        if (mid < y)res = min(res, qrymnd(rs(k), mid + 1, r, x, y));
        return res;
    }
    int bina(int k, int l, int r, int v) {
        if (l == r) {
            if (p[k] < v)return l;
            return l - 1;
        }
        int mid = (l + r) >> 1; pdw(k, l, r, mid);
        if (p[rs(k)] < v)return bina(rs(k), mid + 1, r, v);
        else return bina(ls(k), l, mid, v);
    }
}T;

struct SEGG {
    int mn[N];
    void build(int k, int l, int r) {
        mn[k] = inf;
        if (l == r) {
            return;
        }
        int mid = (l + r) >> 1;
        build(ls(k), l, mid); build(rs(k), mid + 1, r);
    }
    void qry(int k, int l, int r, int res) {
        res = min(res, mn[k]);
        if (l == r) {
            printf("%d ", res);
            return;
        }
        int mid = (l + r) >> 1;
        qry(ls(k), l, mid, res); qry(rs(k), mid + 1, r, res);
    }
    void mdy(int k, int l, int r, int x, int y, int v) {
        if (x <= l && r <= y) {
            mn[k] = min(mn[k], v); return;
        }
        int mid = (l + r) >> 1;
        if (x <= mid)mdy(ls(k), l, mid, x, y, v);
        if (mid < y)mdy(rs(k), mid + 1, r, x, y, v);
    }
}G;


void solve() {
    read(n);
    fs(i, 0, n)wt[i].emplace_back(0);
    fs(i, 1, n) {
        read(a[i]);
        wt[a[i]].emplace_back(i);
    }
    fs(i, 0, n)wt[i].emplace_back(n + 1);
    T.build(1, 1, n);
    G.build(1, 1, n);
    fs(i, 0, n) {
        set<pi>s;
        // cout << "///" << i << endl;
        fs(j, 0, (int)wt[i].size() - 2) {
            int l = wt[i][j] + 1, r = wt[i][j + 1] - 1;
            if (l > r)continue;
            int limr = T.bina(1, 1, n, r + 1);
            if (limr < l)continue;
            int mnd = T.qrymnd(1, 1, n, l, limr);
            s.insert(mpi(mnd, r - l + 1));
            T.mdy(1, 1, n, l, limr, r + 1);
            // cout << "///" << i << ' ' << j << endl;
        }
        // cout << "HHH" << endl;
        vector<int>que;
        que.emplace_back(1);
        for (auto [l, r] : s) {
            // cout << "///" << l << ' ' << r << endl;
            if (que.back() - 1 >= l) {
                que.back() = max(que.back(), r + 1);
            } else {
                que.emplace_back(l - 1);
                que.emplace_back(r + 1);
            }
        }
        que.emplace_back(n);
        // for (int v : que)cout << v << " ";
        // cout << endl;
        for (int j = 0; j < (int)que.size(); j += 2) {
            if (que[j] > que[j + 1])continue;
            G.mdy(1, 1, n, que[j], que[j + 1], i);
        }
    }
    G.qry(1, 1, n, inf);
}

signed main() {
    int T = 1;
    // read(T);
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 27104kb

input:

6
0 0 0 1 2 3

output:

2 3 4 0 0 0 

result:

ok single line: '2 3 4 0 0 0 '

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 28316kb

input:

100
0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1

output:

2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 1st lines differ - expected: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '