QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108212#6105. Double-Colored PapersforeverloseTL 0ms0kbC++143.1kb2023-05-23 21:35:432023-05-23 21:36:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 21:36:52]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-05-23 21:35:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, x, y) for(int i = (x), stOxrj = (y); i <= stOxrj; ++i)
#define irep(i, x, y) for(int i = (x), stOxrj = (y); i >= stOxrj; --i)
#define pb emplace_back
#define all(S) S.begin(), S.end()
#define Size(S) (int)S.size()
#define fi first
#define se second
#define il inline
#define ci const int
#define let const auto
using pii = pair<int, int>;
using vint = vector<int>;
template<typename T>
il void tmax(T &x, const T &y) { if(x < y) x = y; }
template<typename T>
il void tmin(T &x, const T &y) { if(x > y) x = y; }
il int read() {
    int res = 0, flag = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') flag = -1; c = getchar(); }
    while(c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar();
    return res * flag;
}
const int N = (1 << 18) + 20, inf = 0x1f1f1f1f;
int n;
#define ls rt << 1
#define rs rt << 1 | 1
#define mid ((l + r) >> 1)
namespace seg {
	int mn[N], tag[N];
	void pu(int rt) { mn[rt] = tag[rt] + min(mn[ls], mn[rs]); }
	void orz(int rt, int v) { tag[rt] += v, mn[rt] += v; }
    void build() {
        memset(mn, 0x1f, sizeof(mn));
        memset(tag, 0, sizeof(tag));
    }
	void modify(ci lef, ci rig, int v, int rt = 1, int l = 0, int r = n) {
		if(lef <= l && r <= rig) return orz(rt, v);
		if(lef <= mid) modify(lef, rig, v, ls, l, mid);
		if(rig > mid) modify(lef, rig, v, rs, mid + 1, r);
		pu(rt);
	}
    void resets(ci pos, int v, int rt = 1, int l = 0, int r = n) {
        if(l == r) return tmin(mn[rt], v), void();
        v -= tag[rt];
        pos <= mid ? resets(pos, v, ls, l, mid) : resets(pos, v, rs, mid + 1, r);
        pu(rt);
    }
	int query(ci lef, ci rig, int rt = 1, int l = 0, int r = n) {
		if(lef <= l && r <= rig) return mn[rt];
		int res = inf;
		if(lef <= mid) res = query(lef, rig, ls, l, mid);
		if(rig > mid) tmin(res, query(lef, rig, rs, mid + 1, r));
		return res + tag[rt];
	}
}

namespace brute {
    int a[N];
    void build() {
        memset(a, 0x1f, sizeof(a));
    }
    void resets(int x, int v) {
        tmin(a[x], v);
    } 
    void modify(int l, int r, int v) {
        rep(i, l, r) a[i] += v;
    }
    int query(int l, int r)  {
        return *min_element(a + l, a + r + 1);
    }
}
signed main() {
    // freopen("1.in", "r", stdin);
    n = read();
    int np = read(), m = read();
    vint a(n + 1), lsh;
    rep(i, 1, n) a[i] = read(), lsh.pb(a[i]);
    int ans = 0;
    rep(i, 1, np - 1) if(a[i] >= a[np]) ans++;
    sort(all(lsh));
    vint b;
    rep(i, np, n) if(i == np || a[i] > a[np]) b.pb(lower_bound(all(lsh), a[i]) - lsh.begin() + 1);
    int t = Size(b);
    vint f(t, inf);
    f[0] = 0;
    rep(tim, 1, m) {
        vint g(t);
        seg::build();
        rep(i, 0, t - 1) {
            g[i] = seg::query(0, b[i] - 1);
            seg::modify(0, b[i] - 1, 1);
            seg::resets(b[i], f[i]);
        }
        f = g;
    }
    int ans2 = seg::query(0, n);
    cout << (ans2 >= inf ? -1 : ans + ans2) << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

tww
wtw
21

output:


result: